Is there a way to tell Rails to ignore attr_accessible when seeding the database and to allow mass assignment with create or new? I know how to skip validations but do not find anything on mass assignment... -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Markus Proske wrote in post #979510:> Is there a way to tell Rails to ignore attr_accessible when seeding the > database and to allow mass assignment with create or new? > I know how to skip validations but do not find anything on mass > assignment...Here''s one way I found a quick Google search: http://stackoverflow.com/questions/4838716/how-to-avoid-the-validation-callbacks-and-attr-accessible-effects-during-the-s -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thursday, February 3, 2011 11:58:23 PM UTC+1, Ruby-Forum.com User wrote:> > Here''s one way I found a quick Google search: > > > http://stackoverflow.com/questions/4838716/how-to-avoid-the-validation-callbacks-and-attr-accessible-effects-during-the-s >Thank you. I''ve already been there and this works but I was looking for a more global setting for all entries in the seed file. Is there really no other way? Markus -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 4, 8:51 am, Markus Proske <markus.pro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thursday, February 3, 2011 11:58:23 PM UTC+1, Ruby-Forum.com User wrote: > > > Here''s one way I found a quick Google search: > > >http://stackoverflow.com/questions/4838716/how-to-avoid-the-validatio... > > Thank you. I''ve already been there and this works but I was looking for a > more global setting for all entries in the seed file. Is there really no > other way? >Bit hacky but you could override remove_attributes_protected_from_mass_assignment or overwrite the attribute containing the list of protected attributes Fred -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bit hacky but you could override> remove_attributes_protected_from_mass_assignment or overwrite the > attribute containing the list of protected attributes >Thank you! I did not find the remove_attributes_protected..., but did find an interesting method sanitize here: rails<https://github.com/rails/rails/tree/59f7780a3454a14054d1d33d9b6e31192ab2e58b>/ activemodel<https://github.com/rails/rails/tree/59f7780a3454a14054d1d33d9b6e31192ab2e58b/activemodel>/ lib<https://github.com/rails/rails/tree/59f7780a3454a14054d1d33d9b6e31192ab2e58b/activemodel/lib>/ active_model<https://github.com/rails/rails/tree/59f7780a3454a14054d1d33d9b6e31192ab2e58b/activemodel/lib/active_model>/ mass_assignment_security<https://github.com/rails/rails/tree/59f7780a3454a14054d1d33d9b6e31192ab2e58b/activemodel/lib/active_model/mass_assignment_security>/ sanitizer.rb My solution for the archives: seeds.rb module ActiveModel module MassAssignmentSecurity module Sanitizer def sanitize(attributes) attributes end end end end -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Just to save the next person the aggravation of figuring this out, Sanitizer is a class now, not a module, and the sanitize method takes two parameters. So you need this: module ActiveModel module MassAssignmentSecurity class Sanitizer def sanitize(attributes, authorizer) attributes end end end end -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.