From acc76446c5bde88b2412091a2c53886878ed8573 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Fri, 28 Jun 2013 23:34:07 -0400 Subject: [PATCH] Making initial changes to add authorize after update --- lib/cancan/controller_resource.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 702fbcf..94a4c9a 100644 --- a/lib/cancan/controller_resource.rb +++ b/lib/cancan/controller_resource.rb @@ -24,6 +24,10 @@ module CanCan def load_and_authorize_resource load_resource authorize_resource + if update_actions.include?(@params[:action].to_sym) + update_resource + authorize_resource # Reauthorize the now-updated resource + end end def load_resource @@ -86,6 +90,10 @@ module CanCan assign_attributes(resource) end + def update_resource + resource.assign_attributes(resource_params || {}) + end + def assign_attributes(resource) resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource initial_attributes.each do |attr_name, value| @@ -252,6 +260,10 @@ module CanCan [:new, :create] + [@options[:new]].flatten end + def update_actions + [:update] #TODO: check what @options is for + end + private def extract_key(value)