rails 3 : Do i need to give return true in a before_save callback for an object.save to work?

后端 未结 4 1934
伪装坚强ぢ
伪装坚强ぢ 2021-02-18 14:09
Class User  
  before_save :set_searchable

  def set_searchable  
    self.searchable = true if self.status == :active  
  end  
end  

>> u = User.last  
>>         


        
4条回答
  •  离开以前
    2021-02-18 14:43

    Another cleaner way to set boolean columns without return is to use tap

      def set_searchable
        self.tap{|u| u.searchable = status.eql?(:active) }
      end
    

提交回复
热议问题