lib/adeia/controller_resource.rb in adeia-0.2.0 vs lib/adeia/controller_resource.rb in adeia-0.3.0

- old
+ new

@@ -10,24 +10,28 @@ ControllerResource.send(method, controller) end end def self.load_resource_or_records_and_authorize(controller) - if controller.action_name == "index" + case controller.action_name + when "index" controller.authorize_and_load_records! - else + when "new", "create" + controller.authorize! + when "edit", "update", "destroy" controller.load_and_authorize! end end def initialize(controller, **args) @controller = controller @action_name = args.fetch(:action, @controller.action_name) @controller_name = args.fetch(:controller, @controller.controller_path) - @token = args.fetch(:token, @controller.params[:token]) + @token = args.fetch(:token, @controller.request.GET[:token]) @resource = args[:resource] @user = @controller.current_user + store_location end def load_resource begin @resource = resource_class.find(@controller.params.fetch(:id)) @@ -78,9 +82,20 @@ end end def resource_name resource_class.model_name.element + end + + + # Store the current url in a cookie + # + # * *Args* : + # + # * *Returns* : + # + def store_location + @controller.request.cookie_jar[:return_to] = @controller.request.fullpath end end end \ No newline at end of file