Class: FreditController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- FreditController
- Defined in:
- app/controllers/fredit_controller.rb
Constant Summary collapse
- CSS_DIR =
Rails.root + 'public/stylesheets/**/*.css'
- JS_DIR =
Rails.root + 'public/javascripts/**/*.js'
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
46 47 48 49 50 |
# File 'app/controllers/fredit_controller.rb', line 46 def create @path = secure_path params[:file] FileUtils::mkdir_p File.dirname(@path) File.open(@path, 'w') {|f| f.write("REPLACE WITH CONTENT")} end |
#index ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/controllers/fredit_controller.rb', line 8 def index @path ||= secure_path(params[:file] || params[:new_path] || Fredit.editables[:views].first) if !File.size?(@path) File.open(@path, 'w') {|f| f.write("REPLACE WITH CONTENT")} end @source = File.read(Rails.root + @path) end |
#update ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/fredit_controller.rb', line 16 def update @path = secure_path params[:file_path] edit_msg = !params[:edit_message].blank? ? params[:edit_message] : "unspecified edit" = (session[:commit_author] = params[:commit_author]) if session[:commit_author].blank? flash.now[:notice] = "Edited By must not be blank" @source = params[:source] render :action => 'index' return end if params[:commit] =~ /delete/i `git rm #@path` flash[:notice] = "#@path deleted" `git commit --author='#{author}' -m '#{edit_msg}' #{@path}` @path = nil else n = params[:source].gsub(/\r\n/, "\n") File.open(@path, 'w') {|f| f.write(n)} `git add #{@path}` flash[:notice] = "#@path updated" `git commit --author='#{author}' -m '#{edit_msg}' #{@path}` end params.delete(:source) redirect_to :action => 'index', :file => @path end |