Robert Walker wrote:
>> Is there an obvious nicer way I'm missing?
> 
> class User << ActiveRecord::Base
>   attr_accessible :name, :email
>   ...
>   ...
> end
> 
> Only :name and :email is allowed to be set through mass assignment.

Hum. After taking a second look I may have misread your question. I 
missed that you were already using attr_protected. I typically use the 
"while list" method using attr_accessible.

In any case I think I have a better understanding of your question now. 
Since attr_accessible prevents it's list of attributes from being 
updated via update_attributes (mass assignment) then you would need to 
set them individually.

I'm surprised that those values would be coming though the params hash 
at all (as shown in your example). I would expect that the protected 
attributes would be set in a more direct manner, but I haven't fully 
thought this through.

I can't think of the benefit of having :name and :email as protected 
attributes and then take them from user input. What's the benefit over 
allowing them though mass assignment? It appears to me that your code is 
replacing mass assignment with another form of mass assignment.
-- 
Posted via http://www.ruby-forum.com/.
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to