From c2c0b86c3a6ded6fb8ccbd85d2faa5e2221d5c23 Mon Sep 17 00:00:00 2001 From: mccraig mccraig of the clan mccraig Date: Wed, 11 Jan 2012 17:23:35 +0000 Subject: [PATCH] initialise attributes after a resource is created by an InheritedResources controller --- lib/cancan/inherited_resource.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/cancan/inherited_resource.rb b/lib/cancan/inherited_resource.rb index 81bca5b..301724a 100644 --- a/lib/cancan/inherited_resource.rb +++ b/lib/cancan/inherited_resource.rb @@ -6,7 +6,13 @@ module CanCan @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