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.
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:
The title doesn't match the question.
Yes, DB fields are automatically attributes (depending on what you mean by attribute; they're not simply @column_name
as with attr_accessor
).
You can provide some level of accessibility by using attr_accessible
and attr_protected
, but that's for mass-assignment, not general access.