create an empty whitelist of attributes available for mass-assignment for all models

87 views
Skip to first unread message

marcolinux

unread,
Mar 25, 2012, 3:03:41 AM3/25/12
to mon...@googlegroups.com
Hello,
is there a mongoid equivalent of the activerecord config flag

config.active_record.whitelist_attributes = true

in Mongoid?

I found a fairly old post on the group, but I could not find a clear answer nor example.

What AR is doing is not very special (basically passing nil to Active Model if my understanding is correct).

ActiveSupport.on_load(:active_record) do
        if app.config.active_record.delete(:whitelist_attributes)
          attr_accessible(nil)
        end
        app.config.active_record.each do |k,v|
          send "#{k}=", v
        end
      end

As Mongoid is very tight to Active Model, it should be possible to implement a similar configuration parameter.

Thanks,
Marco

Benedikt Deicke

unread,
Mar 25, 2012, 8:25:53 AM3/25/12
to mon...@googlegroups.com
Hi Marco,

here is my simple approach to this: https://gist.github.com/1977438

I'd appreciate a configuration option in Mongoid, too :)

Regards,

Benedikt

marcolinux

unread,
Mar 27, 2012, 8:36:46 AM3/27/12
to mon...@googlegroups.com
Thanks a lot Benedikt,
I will integrate your suggestion waiting for configuration options.
I like 'simple approaches' :-)

Regards,
Marco


On Sunday, March 25, 2012 9:25:53 PM UTC+9, Benedikt wrote:
Hi Marco,

here is my simple approach to this: https://gist.github.com/1977438

I'd appreciate a configuration option in Mongoid, too :)

Regards,

Benedikt


Am 25.03.2012 um 09:03 schrieb marcolinux:

Nick Hoffman

unread,
Mar 29, 2012, 11:33:17 AM3/29/12
to mon...@googlegroups.com
On Sunday, 25 March 2012 08:25:53 UTC-4, Benedikt wrote:
Hi Marco,

here is my simple approach to this: https://gist.github.com/1977438

I'd appreciate a configuration option in Mongoid, too :)

Regards,

Benedikt


I use a very similar approach to Benedikt's, and it's working beautifully for me. 
Reply all
Reply to author
Forward
0 new messages