101

In my routes.rb I have the following:

resources :message_threads

When I call:

message_threads_path(1)

I get:

/message_threads.1

Why is this? My other resources work fine. Am I not pluralizing this correctly or something?

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
ghempton
  • 7,777
  • 7
  • 48
  • 53

3 Answers3

154

Yes, this is a pluralization error.

By passing the ID 1, I assume that you wish to display a single record.

So you need to use the singular 'message_thread':

message_thread_path(1)

Which will yield:

http://localhost:3000/message_threads/1
Scott
  • 17,127
  • 5
  • 53
  • 64
  • 4
    Heh. It happens to us all; frequently. Probably won't be the last time you see this error! – Scott Apr 15 '11 at 08:59
  • I'm getting this very same error with a named route I created and I'm not pluralizing it. What would be the fix there? – kakubei Jul 30 '12 at 14:36
  • 1
    @kakubei, check your routes file. Are you calling `resources :my_model` or `resources :my_models`? (You need to pluralize in the routes file.) – JellicleCat Sep 06 '13 at 21:21
  • All my routes are pluralized. – kakubei Sep 28 '13 at 07:19
  • 1
    Just gone 5pm, was about to bash my head against the keyboard, this was it. Thanks man. – Phantomwhale Nov 21 '13 at 06:10
  • I am using resources :quizzes, and see this in rake routes, api_quizzes POST /api/quizzes(.:format) api/v1/quizzes#create {:format=>"json"} Are you saying that the 'rake routes' command has a bug in it? – Kamilski81 Mar 26 '14 at 21:27
20

Sometimes this also is when you don't provide an :as parameter in your route:

delete "delete/:id" => "home#delete"

Changed to:

delete "delete/:id" => "home#delete", as: :delete

(ignore the odd example, just happened to be something we just ran into for an internal app we're building)

Jamon Holmgren
  • 23,738
  • 6
  • 59
  • 75
  • 5
    This worked for me. Specifying **:as** gave me a name that I could append "_path" to and have Rails know what the hell I was asking for in link_to. Originally, when my routes file had: `match "/xyz/show/:project_id" => "xyz#show_project", :via => [:get]` my view markup: `<%= link_to "Show Details", xyz_show_path(@project) %>` kept producing: `http://localhost:3000/xyz/show.1` Changing the routes file to: `match "/xyz/show/:project_id" => "xyz#show_project", :via => [:get], :as => "show"` allowed: `<%= link_to "Show Details", show_path(@project) %>` to work. – ayang May 22 '13 at 18:50
1

Other folks that land here might be in this situation:

If you have a singular resource declared in your routes.rb:

resource :map

You don't need to pass an object to map_path. Attempting to call map_path(map) will result in similar behavior (i.e. a URL like map.12).

techpeace
  • 2,606
  • 1
  • 22
  • 21