Alex Rivera | Logout

How to make all model attributes accessible for mass-assignment?

Asked 2012-01-22T15:02:22.833
15

I have made all attributes in a rails app not accessible using this application configuration option:

config.active_record.whitelist_attributes = true

In most cases I define a few attributes I want to be accessible as accessible using attr_accessible in models. How do I make all attributes of a particular model accessible. Something like attr_accessible :all.

Edit
Report

1 Answer

13

I've found this approach more readable:

class User < ActiveRecord::Base
  attr_accessible *column_names
end

Changing config.active_record.whitelist_attributes will affect all your models, whereas this will only apply to the one model.

The attr_protected way also works, but I find it confusing (since it's doing the opposite of what it seems to say at first glance).

answered 2013-04-10T17:34:12.493

Your Answer