Rails 4: Skip callback

前端 未结 4 1576
清酒与你
清酒与你 2021-01-17 21:16

I have an auction and a bid object in my application, when someone presses the BID BUTTON it then calls the BID CREATE controller which cre

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-17 21:53

    You can use update_columns See this http://edgeguides.rubyonrails.org/active_record_callbacks.html#skipping-callbacks

    Is there any specific condition like when you don't have endtime then only you need to set end time if that the you can do

    def set_endtime 
       if endtime.nil? 
         self.endtime=self.starttime+self.auctiontimer 
       end 
    end 
    

    OR

    before_update :set_endtime if: Proc.new { |obj| obj.endtime.nil? }
    

提交回复
热议问题