Topic: links

I have to say thank to call and i am sure this is a rookie mistake but i am still trying to get in to the rails thing.

I am trying to create a link

<%= link_to "Home", home_path %>

but when i do i get this error

No route matches {:action=>"show", :controller=>"home"}

rake routes

root        /                        home#index
home_index GET    /home/index(.:format)    home#index
           GET    /home(.:format)          home#index
           POST   /home(.:format)          home#create
  new_home GET    /home/new(.:format)      home#new
 edit_home GET    /home/:id/edit(.:format) home#edit
      home GET    /home/:id(.:format)      home#show
           PUT    /home/:id(.:format)      home#update
           DELETE /home/:id(.:format)      home#destroy

Re: links

Look at this part of the routes:

home GET    /home/:id(.:format)      home#show

This is the route for the show action.  It's for showing one home object. Note that it includes "/:id", so you need to provide this id for the route to work.

Without seeing more of your controller and view code, I can't tell you exactly how to provide it, but in general it will look something like this:

<%= link_to "Home", home_path(home.id) %>

Last edited by Brian71 (2012-04-20 12:46:16)

Re: links

Thanks that was really helpful but i am just trying to get to this rout

home_index GET    /home/index(.:format)    home#index

http://localhost:3000/home/

and i where i can see some basic content of the page.

Last edited by moiseszaragoza (2012-04-23 09:27:43)

Re: links

Try this then:

<%= link_to "Home", home_index_path %>

Re: links

Thanks again that was just what i needed.