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

后端 未结 4 1943
伪装坚强ぢ
伪装坚强ぢ 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:40

    From: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

    If a before_* callback returns false, all the later callbacks and the associated action are cancelled. If an after_* callback returns false, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks defined as methods on the model, which are called last.

    So, yes.

提交回复
热议问题