femto Zheng
2012-Aug-15 10:04 UTC
How to enable activerecord whitelist_attributes in non-Rails environment?
Hello all, I''m developing a sinatra application and loads ActiveRecord in, sometimes it will just report warning for mass for attributes, how can I enable it in non-Rails environment? checked in rails code, it''s config.active_record.whitelist_attributes true, so I add to my top code of sinatra ActiveRecord::Base.whitelist_attributes=true but no luck, no such method exists in ActiveRecord::Base, so what''s the class of config.active_record, and when setting whitelist_attributes = true, in what point it invokes some method of active_record to make it whitelist_attributes aware? Thanks. Best Regards -- 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 https://groups.google.com/groups/opt_out.
Jordon Bedwell
2012-Aug-15 14:49 UTC
Re: How to enable activerecord whitelist_attributes in non-Rails environment?
On Wednesday, 15 August 2012 05:04:44 UTC-5, femto wrote:> > Hello all, I''m developing a sinatra application and loads ActiveRecord in, > sometimes it will just report warning for mass for attributes, > how can I enable it in non-Rails environment? > checked in rails code, it''s config.active_record.whitelist_attributes = > true, > so I add to my top code of > sinatra ActiveRecord::Base.whitelist_attributes=true > but no luck, no such method exists in ActiveRecord::Base, > so what''s the class of config.active_record, and when > setting whitelist_attributes = true, > in what point it invokes some method of active_record to make > it whitelist_attributes aware? > Thanks. > Best Regards >module MyApplication module MyMassAssignmentIncluder extend ActiveSupport::Concern included do attr_accessible(nil) self.mass_assignment_sanitizer = :strict end end end # MyModel < ActiveRecord::Base # include MyApplication::MyMassAssignmentIncluder # 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/6utJ_1YhI34J. For more options, visit https://groups.google.com/groups/opt_out.
femto Zheng
2012-Aug-19 12:48 UTC
Re: How to enable activerecord whitelist_attributes in non-Rails environment?
Hello, thanks very much. On Wed, Aug 15, 2012 at 10:49 PM, Jordon Bedwell <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> On Wednesday, 15 August 2012 05:04:44 UTC-5, femto wrote: >> >> Hello all, I''m developing a sinatra application and loads ActiveRecord >> in, >> sometimes it will just report warning for mass for attributes, >> how can I enable it in non-Rails environment? >> checked in rails code, it''s config.active_record.**whitelist_attributes >> = true, >> so I add to my top code of sinatra ActiveRecord::Base.** >> whitelist_attributes=true >> but no luck, no such method exists in ActiveRecord::Base, >> so what''s the class of config.active_record, and when >> setting whitelist_attributes = true, >> in what point it invokes some method of active_record to make >> it whitelist_attributes aware? >> Thanks. >> Best Regards >> > > module MyApplication > module MyMassAssignmentIncluder > extend ActiveSupport::Concern > > included do > attr_accessible(nil) > self.mass_assignment_sanitizer = :strict > end > end > end > > # MyModel < ActiveRecord::Base > # include MyApplication::MyMassAssignmentIncluder > # 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/6utJ_1YhI34J. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- http://hi.baidu.com/femto http://www.aisiming.com/ http://maptu.heroku.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 https://groups.google.com/groups/opt_out.