gpt4 book ai didi

ruby-on-rails - Ruby 链接到 home#index _path

转载 作者:行者123 更新时间:2023-12-03 18:10:52 39 4
gpt4 key购买 nike

我是 ruby​​ 的新手,我需要帮助。

在我的“app\view\home\index”-> 本地主机上
我有

<%= link_to "Blog", posts_path %>

这导致我 -> localhost/posts

到目前为止,一切都很好。
现在这里是问题统计的地方。

在我的“app\view\posts\index” -> localhost/posts
我有
<%= link_to "Home" %>

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

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

我的路线.rb:
BIO::Application.routes.draw do

root :to => 'home#index'

get "home/index"

resources :posts do

resources :comments end

最佳答案

将 root_path 添加到 link_to 的末尾

<%= link_to "Home", root_path %>

关于ruby-on-rails - Ruby 链接到 home#index _path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7955346/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com