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

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

    If you using store attributes like this

    store :settings, accessors: [:volume_adjustment] 
    

    or using gems like hstore_accessor gem link

    So you ended up using store method on model, then to override those method you can't use self.read_attribute, you must use instead super like that:

    def partner_percentage
      super.to_i || 10
    end
    

提交回复
热议问题