ruby - Rails ActiveModel::Dirty in a form -


when using rails form update boolean value (in case shipped), how can check see if has been set (specifically) false true, in order set shipped_at variable?

at moment, update action looks this:

  def update     @order = @current_shop.orders.find(params[:id])      if @order.update_attributes(params[:order])       redirect_to edit_admin_shop_order_path(@current_shop, @order), notice: 'order updated.'     else       render action: "edit"     end   end 

this condition needs checked, shipped_at should assigned (if condition holds) , obviously, object should saved.

should use activemodel::dirty? how should controller action @ end of day?

i think responsibility of model order itself.

class order < activerecord::base   before_update :set_shipped_at    def set_shipped_at     if self.shipped_was == false && self.shipped == true       self.shipped_at = time.now     end   end end 

now don't need change in controller , if save order piece of code shipped_at value set.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -