foo_path not defined

I have the usual:

config/routes.rb: NewApp::Application.routes.draw do   match('blahs/:item' => 'blahs#show', :constraints => { :item => /.*/ }) end

app/view/blahs/show.html.erb: <%= link_to "blah", blahs_path(9999) %>

But I'm getting this error: undefined method `blahs_path' for #<#<Class:0x007f96083474c0>:0x007f960509b288>

I've tried blah_path, blahs_path, blah_url, and blahs_url.

What am I doing wrong?

I'm using Rails 3.2. This is my first Rails 3.2 app but I've used Rails 2.x for a long time. I can't figure out what I'm doing wrong.

I believe that if you want to use blah_path(id) (it should be blah not blahs) then you have to have resources :blahs in your routes. If you have not got resourceful routes then you can still say blah_path( @blah ). See the Rails Guide on Routing. I have to say I am not 100% certain about the above however.

Colin

Thanks.

I checked Rails Routing from the Outside In — Ruby on Rails Guides first. The code I have, to my eyes, match the lead examples in sections 1.1 and 1.2. There must be something I'm overlooking.

Please quote the previous message when replying so that it is easier to follow the thread. Anyone reading this will now have to look back at previous messages to check your code (myself included).

1.1 of the guide does not include the use of _path, 1.2 has the code <%= link_to "Patient Record", patient_path(@patient) %> note that this uses @patient as the parameter, not an id as in your example.

Section 2.3 shows the use of photo_path(id) where resourceful routes are used as I said in my previous post, but you have not specified a resourceful route.

Colin

Colin Law wrote in post #1063357:

Thanks.

I checked Rails Routing from the Outside In — Ruby on Rails Guides first. The code I have, to my eyes, match the lead examples in sections 1.1 and 1.2. There must be something I'm overlooking.

Please quote the previous message when replying so that it is easier to follow the thread. Anyone reading this will now have to look back at previous messages to check your code (myself included).

1.1 of the guide does not include the use of _path, 1.2 has the code <%= link_to "Patient Record", patient_path(@patient) %> note that this uses @patient as the parameter, not an id as in your example.

Section 2.3 shows the use of photo_path(id) where resourceful routes are used as I said in my previous post, but you have not specified a resourceful route.

Colin

Sorry... I'm reading this from the forum interface and didn't consider people reading it via email.

You are correct. I added

  resources :pogos

to routes.rb and now I can do:

<%= link_to "pogo", pogo_path(1234) %>

in my view.

I thought resources were just a batch of named routes and I thought what I did before was a named route. I need to go check on that.

What confuses me is that blah_path is not even defined. It seems like if it needed a particular type of argument, then the error would be inside blah_path -- not in the code trying to find the blah_path method.

I wonder if Rails is eating the top of the exception stack which might help me understand what is really happening in this case.

Thank you for your time.

Colin Law wrote in post #1063357:

Thanks.

I checked Rails Routing from the Outside In — Ruby on Rails Guides first. The code I have, to my eyes, match the lead examples in sections 1.1 and 1.2. There must be something I'm overlooking.

Please quote the previous message when replying so that it is easier to follow the thread. Anyone reading this will now have to look back at previous messages to check your code (myself included).

1.1 of the guide does not include the use of _path, 1.2 has the code <%= link_to "Patient Record", patient_path(@patient) %> note that this uses @patient as the parameter, not an id as in your example.

Section 2.3 shows the use of photo_path(id) where resourceful routes are used as I said in my previous post, but you have not specified a resourceful route.

Colin

Sorry... I'm reading this from the forum interface and didn't consider people reading it via email.

You are correct. I added

resources :pogos

to routes.rb and now I can do:

<%= link_to "pogo", pogo_path(1234) %>

in my view.

I thought resources were just a batch of named routes and I thought what I did before was a named route. I need to go check on that.

What confuses me is that blah_path is not even defined. It seems like if it needed a particular type of argument, then the error would be inside blah_path -- not in the code trying to find the blah_path method.

Did you name the route in your routes file (ie :as => "blah")?

Jeremy W. wrote in post #1063404: