When I use the attr_accessible
to specify which fields from my Model I will expose, is it true for script/console as well? I mean something that I didn't specify as attr_accessible
won't be accessible as well through console ?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
I found why:
Specifies a white list of model attributes that can be set via mass-assignment, such as
new(attributes)
,update_attributes(attributes)
, orattributes=(attributes)
. This is the opposite of the attr_protected macro:So it means that it just avoid mass-assignment but i can still set a value.
If you want to expose a field form your model, you can use
or if you want add some behaviour to your attribute, you ll have to use virtual attributes
cheers.
This is only true for mass assignment. For instance, if you were to set
attr_protected :protected
in your model:Conversely, you could set all attributes you want as accessible using
attr_accessible
.However, the following will still work:
This is the same behaviour as in controllers, views, etc.
attr_protected
only protects against mass assignment of variables, primarily from forms, etc.The console behaves exactly as your Rails application. If you protected some attributes for a specific model, you won't be able to mass assign these attributes either from console or from the Rails app itself.
When you specify somethings to be
attr_accessible
only those things can be accessed in console or by website Interface.eg: Suppose you made
name
andemail
to beattr_accessible
:and left out
created_at
andupdated_at
(which you are supposed to). Then you can only edit/update those fields in console.