anemaria20
anemaria20

Reputation: 1728

Rails URL doesn't show, only the view renders

I have this route:

get 'events/new' => 'events#new'

and for this, an appropriate action and a template with form_for accepting an empty @event model object:

<%= form_for(@event) do |f| %>

Now, I also have this route:

post '/events' => 'events#hey'

and inside the hey action I don't do anything but let the view template take over which displays some static content.

Here's the problem: When I go to site.com/events/new, enter anything and click on the submit button, Rails redirects me to site.com/events/, displaying the content of the hey.html.erb view template!

Is this expected behavior? What I expected was to go to site.com/events/hey. Is there some implicit redirect of form_for does after the POST request?

Upvotes: 0

Views: 48

Answers (1)

luissimo
luissimo

Reputation: 978

Your post '/events' => 'events#hey' brings you to '/events' where you just render the hey.html.erb template, but that doesn't change the url. What you want to do is this:

post '/events/hey' => 'events#hey'

Upvotes: 1

Related Questions