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

前端 未结 7 1614
无人共我
无人共我 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:39

    The Rails Style Guide recommends using self[:attr] over read_attribute(:attr).

    You can use it like this:

    def name
      name_trans || self[:name]
    end
    
    0 讨论(0)
提交回复
热议问题