create
update
class RestaurantsController < ApplicationController
def update
@restaurant = Restaurant.find(params[:id])
unless @restaurant.update_attributes(params[:restaurant])
# error while saving: warn user, etc
return # stops execution
end
# restaurant was saved ok, do the additional things you want
StatusUpdate.create :user_id => @restaurant.user_id,
:comment => "I just ate @ #{@restaurant.name}"
flash[:notice] = 'Restaurant was successfully updated, and a status update was added.'
redirect_to :action => 'list'
end
end
class Restaurant < ActiveRecord::Base
after_save :append_status_update
private
def append_status_update
StatusUpdate.create :user_id => self.user_id,
:comment => "I just ate @ #{self.name}"
end
end