Reputation: 71
I am new to ruby and I need help.
on my "app\view\home\index" -> localhost I got
<%= link_to "Blog", posts_path %>
that leads me to -> localhost/posts
so far so good. now here is where the problem stats.
on my "app\view\posts\index" -> localhost/posts I got
<%= link_to "Home" %>
That links me to the same page "localhost/posts" but I want it to link to "localhost"
I have tried almost anything but without success.
my routes.rb:
BIO::Application.routes.draw do
root :to => 'home#index'
get "home/index"
resources :posts do
resources :comments end
Upvotes: 7
Views: 14308
Reputation: 1124
Use 'rake routes' to see where you can route your application links. And after name of your link try to use ways from this route list, it is more complex then controller/action/id, but real rails way.
Upvotes: 3
Reputation: 4687
link_to has several signatures
The most common link_to signature uses two parameters: the first one is the text that will appear in the link. The second parameter is the destination URL (i.e. the URL where the user will go after following the link) If you omit the second parameter, an empty link will be made, and that the reason why you don't change the page.
If you write link_to "Home", root_path as Milan suggested, you'll get a full working link
Upvotes: 1
Reputation: 5646
add root_path to end of link_to
<%= link_to "Home", root_path %>
Upvotes: 25