I have two models: Schedule and Project. Project has_one Schedule and Schedule belongs_to Project. When I create a schedule, I do:
def create
@schedule = Schedule.new(schedule_params)
@schedule.project = Project.find(params[:project_id])
if @schedule.save
flash[:notice] = "Successfully created schedule."
redirect_to profile_path(current_user)
end
end
This works. However, I added an after_create callback and an after_update callback to make notifications. A 'new schedule created' notification when the schedule is created, and a 'your schedule has been updated' notification when it is updated. The problem is that in the controller I use @schedule.new and @schedule.save, not @schedule.create. I need to change my controller code to use .create so the after_create callback will work. I have already tried using the after_save callback, but that gets called whenever the schedule is updated as well so that won't work.
Because of the way I define @schedule and @schedule,project, I cannot figure out how to change the code I have above to use @schedule.create. Does anyone have any ideas? Thanks.