usage of attr_accessor in Rails

前端 未结 5 645
不思量自难忘°
不思量自难忘° 2020-11-27 05:53

When do you use attr_reader/attr_writer/attr_accessor in Rails models?

5条回答
  •  自闭症患者
    2020-11-27 06:25

    If you are using it to validate the acceptance of the terms_of_service, you should really consider using validates :terms_of_service, :acceptance => true. It will create a virtual attribute and is much more concise.

    http://guides.rubyonrails.org/active_record_validations.html#acceptance.

提交回复
热议问题