Route helpers are not working

Hey all,

I find this in ruby guide:

resources :photos do
collection do
get ‘search’
end
end
It will also create the search_photos_url and search_photos_path route
helpers.

So I try to implement:

#routes
resources :core do
collection do
get ‘coreim’
get ‘corer’
end
end

#index.html.haml
= link_to ‘core’, coreim_core_path

I get undefined method coreim_core_path

Thanks for response

Phil

On Wed, Mar 30, 2011 at 10:45 AM, John M. [email protected]
wrote:

helpers.

#index.html.haml
= link_to ‘core’, coreim_core_path

I get undefined method coreim_core_path

run ‘rake routes’ on the command line to see the routes that were
created.

Excerpts from John M.'s message of Wed Mar 30 08:45:50 -0700 2011:

So I try to implement:

#routes
resources :core do
collection do
get ‘coreim’
get ‘corer’
end
end

With that routes file:

$ rake routes
coreim_core_index GET /core/coreim(.:format) {:action=>“coreim”,
:controller=>“core”}
core_index GET /core(.:format) {:action=>“index”,
:controller=>“core”}
POST /core(.:format) {:action=>“create”,
:controller=>“core”}
new_core GET /core/new(.:format) {:action=>“new”,
:controller=>“core”}
edit_core GET /core/:id/edit(.:format) {:action=>“edit”,
:controller=>“core”}
core GET /core/:id(.:format) {:action=>“show”,
:controller=>“core”}
PUT /core/:id(.:format) {:action=>“update”,
:controller=>“core”}
DELETE /core/:id(.:format) {:action=>“destroy”,
:controller=>“core”}

So you would have +coreim_core_index_path+, for example.

This rather surprised me, since I had the same expectations as you.
Further
investigation suggestions inflections are to blame.

config/routes.rb

Note that we changed the resource to a pluralized form: “cores”

instead of “core”.
resources :cores do
collection do
get ‘coreim’
get ‘corer’
end
end

$rake routes
coreim_cores GET /cores/coreim(.:format) {:action=>“coreim”,
:controller=>“cores”}
cores GET /cores(.:format) {:action=>“index”,
:controller=>“cores”}
POST /cores(.:format) {:action=>“create”,
:controller=>“cores”}
new_core GET /cores/new(.:format) {:action=>“new”,
:controller=>“cores”}
edit_core GET /cores/:id/edit(.:format) {:action=>“edit”,
:controller=>“cores”}
core GET /cores/:id(.:format) {:action=>“show”,
:controller=>“cores”}
PUT /cores/:id(.:format) {:action=>“update”,
:controller=>“cores”}
DELETE /cores/:id(.:format) {:action=>“destroy”,
:controller=>“cores”}


med vnlig hlsning
David J. Hamilton

Excerpts from David J. Hamilton’s message of Wed Mar 30 09:22:01 -0700
2011:

This rather surprised me, since I had the same expectations as you. Further
investigation suggestions inflections are to blame.

suggestions → suggests.

med vänlig hälsning
David J. Hamilton

Thanks for response, it outputs this:

coreim_core_index GET /core
/coreim(.:format) {:action=>“coreim”,
:controller=>“core”}
corer_core_index GET /core/corer(.:format)
{:action=>“corer”, :controller=>“core”}

So I would expect this to work:

coreim_core_path
corer_core_path

But neither does. This doesn’t work either:

coreim_core_index
corer_core_index

$rake routes
coreim_cores GET /cores/coreim(.:format) {:action=>“coreim”,
:controller=>“cores”}
cores GET /cores(.:format) {:action=>“index”,
:controller=>“cores”}

ah, thanks for response. I didnt see this message on my last response.

Phil

On Wed, Mar 30, 2011 at 11:30 AM, John M. [email protected]
wrote:

coreim_core_path
corer_core_path

But neither does. This doesn’t work either:

coreim_core_index
corer_core_index

For the record, if rake routes gives you the name coreim_core_index,
then
the named route will be coreim_core_index_path or
coreim_core_index_url…
not just coreim_core_index by itself. If you’re changing the route
names,
that may not matter. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs