Permalink
Browse files

initialise attributes after a resource is created by an

InheritedResources controller
  • Loading branch information...
1 parent 9eebeb2 commit 681ca690a389f85e59b5d12430a9799fe12e041d @mccraigmccraig mccraigmccraig committed Jan 11, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/cancan/inherited_resource.rb
@@ -6,7 +6,13 @@ def load_resource_instance
@controller.send :association_chain
@controller.instance_variable_get("@#{instance_name}")
elsif new_actions.include? @params[:action].to_sym
- @controller.send :build_resource
+
+ resource = @controller.send :build_resource
+ initial_attributes.each do |attr_name, value|
+ resource.send("#{attr_name}=", value)
+ end
+ resource
+
else
@controller.send :resource
end

0 comments on commit 681ca69

Please sign in to comment.