Ruby on rails 模型法中的记录更新

Ruby on rails 模型法中的记录更新,ruby-on-rails,model-view-controller,ruby-on-rails-4,Ruby On Rails,Model View Controller,Ruby On Rails 4,在我的Rails 4应用程序中,我目前正在将我的逻辑转移到我的模型中 我的模型中的一种方法更改预订的状态: def withdraw if self.status == 1 #only allow bookings with status 1 to be updated self.status = 2 GuestMailer.booking_withdrawn(self).deliver save! end end 我从我的BookingController调用

在我的Rails 4应用程序中,我目前正在将我的逻辑转移到我的模型中

我的模型中的一种方法更改预订的状态:

def withdraw
  if self.status == 1 #only allow bookings with status 1 to be updated
    self.status = 2
    GuestMailer.booking_withdrawn(self).deliver
    save!
  end
end
我从我的BookingController调用该方法,如下所示:

if @booking.withdraw
  flash[:success] = 'The booking has been withdrawn'
end

我的问题是我应该使用
save在模型中,因为我只是在更新?

您可以使用
保存。但是,该方法可以重命名为
draw
显示此方法更改对象的状态,并在无法保存模型时引发异常