I have an update method in a controller. If params[:single] is a value of 1, I want to run a create_exception method that looks like this and not update the record:
before_action :create_exception, only: %i[ update ]
def update
if @event.update(event_params) ...
end
private
def create_exception
if params[:single] == 1
@exception = @event.event_exceptions.create(date: params[:exception_date])
respond_to do |format|
format.turbo_stream
format.html { redirect_to events_path, notice: "Event was successfully updated." }
format.json { head :no_content }
end
end
end
My first problem is that the create_exception method does not seem to be firing when I update an event. It just calls update and updates the info on the record which is not what I want. If params[:single] = 1 I want to create an expection and redirect back to the schedule without updating the event.
What is the best way to accomplish this?