0

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.

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
B Seven
  • 44,484
  • 66
  • 240
  • 385

2 Answers2

1

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
1

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

rogal111
  • 5,874
  • 2
  • 27
  • 33