Search code examples
ruby-on-railsrubyruby-on-rails-3attributesaccess-specifier

How do you designate private or protected attributes in Ruby/Rails?


How do you designate private or protected attributes in Ruby/Rails?

Are all DB fields automatically attributes, and don't need to be defined in the Model?

Any recommended tutorials?

Working in Rails 3.0.7.


Solution

  • You can use attr_protected, attr_accessible or attr_readonly

    The attr_protected, attr_readonly and attr_accessible macros control what is accepted for mass-assignment. Read those links if you’re not familiar with the difference between those three macros.

    Documentation of ActiveRecord model:

    http://api.rubyonrails.org/classes/ActiveRecord/Base.html

    http://apidock.com/rails/ActiveRecord/Base