usage of attr_accessor in Rails

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

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

5条回答
  •  臣服心动
    2020-11-27 06:29

    One example is to have a number of options stored in one serialized column. Form builder would complain if you try to have a text field for one of these options. You can use attr_accessor to fake it, and then in the update action save it in the serialized column.

提交回复
热议问题