Ruby链接到home #index _path

Rob*_*ter 4 ruby-on-rails

我是ruby的新手,我需要帮助.

在我的"app\view\home\index" - > localhost我得到了

<%= link_to "Blog", posts_path %>
Run Code Online (Sandbox Code Playgroud)

这导致我 - > localhost/posts

到现在为止还挺好.现在这里是问题属性的地方.

在我的"app\view\posts\index" - > localhost/posts我得到了

<%= link_to "Home" %>
Run Code Online (Sandbox Code Playgroud)

这将我链接到同一页面"localhost/posts"但我希望它链接到"localhost"

我几乎尝试过任何事情,但没有成功.

我的routes.rb:

BIO::Application.routes.draw do

root :to => 'home#index'

get "home/index"

resources :posts do

resources :comments end
Run Code Online (Sandbox Code Playgroud)

Mil*_*ric 21

将root_path添加到link_to的末尾

<%= link_to "Home", root_path %>
Run Code Online (Sandbox Code Playgroud)