Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 676
Robster Avatar asked Nov 28 '22 22:11

Robster


2 Answers

add root_path to end of link_to

<%= link_to "Home", root_path %>
like image 77
Milan Jaric Avatar answered Dec 11 '22 19:12

Milan Jaric


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.

like image 27
antiqe Avatar answered Dec 11 '22 18:12

antiqe