Ruby on Rails attr_accessible and scaffolding
I have recently started building an application in rails (3.0.5). Just to get things moving, I scaffolded one of my models (say, User). Now, the model this creates is a completely bare extension of ActiveRecord::Base
, however the controller makes use of User.create(params[:user])
etc. implying attr_accessible
is be开发者_运维百科ing set.
Some time later (now), after some changes, I'm getting warnings about protected fields in mass assignments, and none of these methods are working! Can anyone help me figure out why this is and why rails would scaffold something that shouldn't work?
Scaffolding and attr_accessible are two completely different things.
When you specify an attribute as accessible, you say that when you try to mass assign(like save) your model, ONLY the accessible values will be updated. So, if you have the username field as accessible and you try to change the password field, the latter will not change and you will get a warning.
Scaffolding on the other hand, is just a quick way to get a RESTful resource up and running fast.
There is really no connection to the two ideas.
精彩评论