Reputation: 5792
I have a question regarding the submissions of forms in rails. I have a form:
<%= form_for Event.new, multipart: true, class: 'form' do |f| %>
In the controller:
def create
@event = Event.new(event_params)
if @event.save
redirect_to dashboard_event_path @event
else
flash[:error] ||= 'Please fix the event\'s details'
render :new
end
Working on a new Event object. (i.e. /events/new) However, when I'm posting that form, and there are validation errors, it will render that form again, but the url will be /events/. is that normal? I know that the routes for new is /new and create is POST to /events, but how do I keep the browser in the /new url?
Help?
Thanks
Upvotes: 0
Views: 29
Reputation: 25030
It's perfectly normal, nothing to be done here. Making the URL stay the same would be changing how Rails works internally - it's really not worth doing that.
Upvotes: 1
Reputation: 7810
That's normal. You are responding from the events method in the controller. Just because you got the html from a file with another name doesn't mean the url will change. If you want the url to change, the easiest thing to do would be to redirect to the new page instead of rendering it
Upvotes: 1