我正在研究https://www.railstutorial.org的第5章。运行我的rails服务器时,页脚链接呈现:“href = localhost:3000 / about”而不是“/ about”。
以下是该视图的相关代码:
<%= link_to "About", about_path %>
<%= link_to "Contact", contact_path %>
这是我的routes.rb:
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
我添加了联系人链接,因为它返回了所需的“/ contact”。这让我有点疯狂。
我也会包含我的测试文件:
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
end
产生的错误是:
SiteLayoutTest#test_layout_links [/sample_app/test/integration/site_layout_test.rb:9]:
Expected at least 1 element matching "a[href="/about"]", found 0..