app/controllers/docushin/routes_controller.rb in docushin-0.0.1 vs app/controllers/docushin/routes_controller.rb in docushin-0.0.2
- old
+ new
@@ -1,36 +1,23 @@
-class Docushin::RoutesController < ActionController::Base
- layout 'docushin'
- before_filter :load_route_set
+module Docushin
+ class RoutesController < Docushin::ApplicationController
+ before_filter :load_route_set
+ before_filter :authorize!, :only => [:edit, :update]
- def index
- end
+ def index
+ end
- def show
- @route = @routes_collection.find_by_filename_hash(params[:id])
- end
+ def show
+ @route = @route_set.find(params[:id])
+ end
- def edit
- @route = @routes_collection.find_by_filename_hash(params[:id])
- end
+ def edit
+ @route = @route_set.find(params[:id])
+ end
- def update
- @route = @routes_collection.find_by_filename_hash(params[:id])
- #create the directory if it doesnt exists
- FileUtils.mkdir_p(@path) unless File.exists?(@path)
-
- File.open(File.join(@path, @route.file_name) + ".md", "w+") do |file|
- file.write "---\n"
- file.write "description: " + params[:route][:description] + "\n"
- file.write "---\n"
- file.write params[:route][:content]
- file.close
+ def update
+ @route = @route_set.find(params[:id])
+ @route.update_attributes(params[:route])
+ redirect_to routes_path
end
- redirect_to routes_path
end
-
- private
- def load_route_set
- @routes_collection = Docushin::RouteSet.new
- @path = File.join(Rails.root, 'doc', 'docushin')
- end
-end
\ No newline at end of file
+end