How can I overwrite a getter method in an ActiveRecord model?

前端 未结 7 1615
无人共我
无人共我 2020-12-13 02:06

I\'m trying to overwrite a getter method for an ActiveRecord model. I have an attribute called name in the model Category, and I\'d like to be able

7条回答
  •  北海茫月
    2020-12-13 02:25

    I would like to add another option for overwriting getter method, which is simply :super.

    def name
      name_trans || super
    end
    

    this works not just on attributes getter method, but also associations getter methods, too。

提交回复
热议问题