【发布时间】:2017-05-06 06:04:02
【问题描述】:
当我在 rails 中使用 link_to 时
我知道表格是
link_to "Profile", profile_path(@profile)
# => <a href="/profiles/1">Profile</a>
但在我的代码中
<% @posts.each do |post|%>
<h2><%=post.title %></h2>
<p><%= post.content%></p>
<%=link_to "show", posts_path(post.id) %>
<%end%>
我希望我的网址看起来像 posts/1
但它是posts.1
【问题讨论】:
-
你可以试试
<%=link_to "show", posts_path(post) %> -
对不起它不起作用:-(
-
能否分享你的routes.rb文件,你需要在你的html文件中添加post_path(post)
标签: ruby-on-rails ruby link-to