Garrett Murphey
Garrett Murphey

Reputation: 135

No route matches in Rails 3.0.4

Been staring at this problem for a while now. Here's the error I'm getting when I try to view the page.

No route matches {:action=>"confirm", :controller=>"locations"}

This is what I have in the view.

<%= form_for(@location, :url => { :action => :confirm }) do |f| %>
<% end %>

And I think my routes file is set up correctly.

Finder::Application.routes.draw do
  resources :locations do
    member do 
      post :confirm
    end
  end

  root :to => 'locations/index'
end

Any ideas?

Updated:

Ran rake routes and get what I think is correct.

confirm_location POST   /locations/:id/confirm(.:format) {:action=>"confirm", :controller=>"locations"}

Upvotes: 5

Views: 5645

Answers (4)

Jonas
Jonas

Reputation: 11

Make sure that form_for doesn't sneak in a hidden field with _method=put if you have declared the route as accepting only post in your routes file.

Upvotes: 1

coreyward
coreyward

Reputation: 80128

You can debug your routes easily in the future by running $ rake routes and looking at the output. ;)

I think what is happening is that your post :confirm isn't registering the route you're expecting. In the guides, match and it's brethren accept a string as a URL segment like so:

resources :locations do
  member do
    post 'confirm'
  end
end

Note that "confirm" is now a string instead of a symbol.

If this doesn't help, run $ rake routes and tack the output onto your question.

Update

After seeing your rake output, I think that you just need to specify the POST method on your form_for:

<%= form_for(@location, :url => { :action => :confirm }, :method => :post) do |f| %>
<% end %>

You can also make this more readable using that helper method that Rails defines:

<%= form_for(@location, :url => confirm_location_path(@location), :method => :post) do |f| %>
<% end %>

Upvotes: 5

Dogbert
Dogbert

Reputation: 222388

Try adding a :method => :post to your form_for

<%= form_for(@location, :url => { :action => :confirm }, :method => :post) do |f| %>
<% end %>

Upvotes: 1

Adrian Pacala
Adrian Pacala

Reputation: 1011

Did you define the confirm action in your LocationsController?

Upvotes: 1

Related Questions