Sorry if the question is obvious, I am only starting to work with Rails.
I have a following code in several controller methods now:
respond_to do |format|
if @project.save
format.html { redirect_to(edit_project_url(@project), :notice => '#{user.name} added to #{role}.') }
format.js
else
format.html { render :action => "edit" }
format.js #...
end
end
So the question is, what is the best way to do the same thing for errors in all methods?
Is it recommended that I use save!
and handle it in rescue_action
?
Or should I do my own respond
method and pass save
in a block?