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

Showing 1-4 of 4 messages
create an empty whitelist of attributes available for mass-assignment for all models marcolinux 3/25/12 12:03 AM
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
Re: [mongoid] create an empty whitelist of attributes available for mass-assignment for all models Benedikt Deicke 3/25/12 5:25 AM
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
Re: [mongoid] create an empty whitelist of attributes available for mass-assignment for all models marcolinux 3/27/12 5:36 AM
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:

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
Re: [mongoid] create an empty whitelist of attributes available for mass-assignment for all models Nick Hoffman 3/29/12 8:33 AM
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.