Override ActiveRecord attribute methods

前端 未结 4 1865
臣服心动
臣服心动 2020-12-07 07:39

An example of what I\'m talking about:

class Person < ActiveRecord::Base
  def name=(name)
    super(name.capitalize)
  end
  def name
    super().downcas         


        
4条回答
  •  感情败类
    2020-12-07 08:36

    There is some great information available on this topic at http://errtheblog.com/posts/18-accessor-missing.

    The long and short of it is that ActiveRecord does correctly handle super calls for ActiveRecord attribute accessors.

提交回复
热议问题