Merge pull request #653 from andhapp/fix-pull-request-640

Init attributes in InheritedResources controller w/ specs
This commit is contained in:
Ryan Bates
2012-06-19 10:53:22 -07:00
3 changed files with 24 additions and 1 deletions

View File

@@ -83,6 +83,10 @@ module CanCan
def build_resource
resource = resource_base.new(resource_params || {})
assign_attributes(resource)
end
def assign_attributes(resource)
resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource
initial_attributes.each do |attr_name, value|
resource.send("#{attr_name}=", value)

View File

@@ -6,7 +6,8 @@ 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
assign_attributes(resource)
else
@controller.send :resource
end