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

后端 未结 4 1936
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-18 14:37

    The documentation say

    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.

    BUT

    you might want to check this out ( I have tested this myself and the issue is 100% authentic)

    Plus also there is bug related to before_save you might want to know check the comment over here

    enter image description here

    As said in the comment it is observed sometimes.

    Whatever you do just be aware of that there are some issues with rails callback. This would save your time when you ran into one of those

提交回复
热议问题