When I check to see if my error message is working correctly, I notice my redirect goes to /businesses instead of /businesses/new after it POST (create action). I am using the regular RESTFUL routes but I need it to go back to /businesses/new on POST when their is an error. How can I do this?
This is my current code:
def create
@business = Business.new(params[:business])
if @business.save
redirect_to :back, :notice => "You have successfully added a new business."
else
render :action => 'new', :notice => "Please try again."
end
end
You should not redirect if the validation is failed. Here is what i should do to stay on the same page.