Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support Mass-Assignment Role of ActiveRecord #577

Closed
wants to merge 1 commit into from

8 participants

@jpascal

No description provided.

@Sija Sija referenced this pull request from a commit in Sija/cancan
Sijawusz Pur Rahnama Merged PR #577 b29c5d3
@ramaboo

I ran into this problem as well.. now that attr_accessible takes an :as option it seems like this is an important fix. Any chance of getting it rolled up into the gem?

@ramaboo ramaboo referenced this pull request from a commit
@ramaboo ramaboo fixing #577 d4bd399
@sevenseacat

+1 for adding this!

@pietia
@driehle

+1 would like to see this in cancan!

@jeremyf
Collaborator

@ramaboo I ran the tests and they do not pass on master branch. I'd imagine with a month passing there may be an API change.

Also please remove the white space at the end of # Passing to ActiveRecord for support Mass-Assignment Role in lib/cancan/controller_additions.rb

Hit me up when you get this working.

@andhapp
Collaborator

Can someone write specs around this behaviour? It won't be merged into master without specs. Thanks.

@rvanlieshout

Written some specs for this in #657

@andhapp
Collaborator

Hello all, I am closing this pull request as @rvanlieshout has updated the pull request with some specs. Let's carry on a discussion there (#657).

@andhapp andhapp closed this
@andhapp andhapp referenced this pull request from a commit
@ramaboo ramaboo fixing #577 4f1893f
@andhapp andhapp referenced this pull request from a commit
@ramaboo ramaboo fixing #577 9ff47ea
@ghost Unknown referenced this pull request from a commit in bignerdranch/cancan
@ramaboo ramaboo fixing #577 e3c0992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2012
  1. @jpascal

    Add option :assigment to load_and_authorize_resource for support Mass…

    jpascal authored
    …-Assignment Role of ActiveRecord
This page is out of date. Refresh to see the latest.
View
3  lib/cancan/controller_additions.rb
@@ -112,6 +112,9 @@ def load_and_authorize_resource(*args)
# [:+prepend+]
# Passing +true+ will use prepend_before_filter instead of a normal before_filter.
#
+ # [:+assignment+]
+ # Passing to ActiveRecord for support Mass-Assignment Role
+ #
def load_resource(*args)
cancan_resource_class.add_before_filter(self, :load_resource, *args)
end
View
2  lib/cancan/controller_resource.rb
@@ -82,7 +82,7 @@ def load_collection
end
def build_resource
- resource = resource_base.new(@params[name] || {})
+ resource = resource_base.new(@params[name] || {}, :as => @options[:assignment])
resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource
initial_attributes.each do |attr_name, value|
resource.send("#{attr_name}=", value)
Something went wrong with that request. Please try again.