Uchenna
Uchenna

Reputation: 4089

Mass assignment in rails3.1

Im working on a simple rails project were users have an attribute called is_admin, and the is_admin cannot be assigned through mass asignment(atr_assecsible). The problem here is, i want to create a default user with the value is_admin => true and i do not no if it would be possible from the migration file because of the protected attribute(:is_admin). so that wen i run rake rails:setup it creates the migrations and the default admin user.

Upvotes: 0

Views: 617

Answers (3)

Guilherme Garnier
Guilherme Garnier

Reputation: 2257

BTW, without_protection parameter works only on Rails 3.1

Upvotes: 0

kain
kain

Reputation: 5570

If you are using a recent Rails version:

MyModel.create({my_attr: 1, is_admin: true}, without_protection: true)}

or you can look into the as: option

attr_accessible :is_admin, as: :admin
MyModel.create({my_attr: 1, is_admin: true}, as: :admin)}

Upvotes: 0

Eric R.
Eric R.

Reputation: 983

To my knowledge, migrations don't use mass assignment. I don't see why you would have an issue doing this.

Upvotes: 2

Related Questions