Robster
Robster

Reputation: 71

Ruby Link to home#index _path

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

Answers (3)

antiqe
antiqe

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

Ricardo Amores
Ricardo Amores

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

Milan Jaric
Milan Jaric

Reputation: 5646

add root_path to end of link_to

<%= link_to "Home", root_path %>

Upvotes: 25

Related Questions