1

我是 Rails 新手,现在正在学习路由,这就是我的routes.rb

match '/text' => 'text#index'
match '/text/:id' => 'text#show'

这是我的app/views/text/index.html.erb

<h1>Texts</h1>
<% @texts.each do |t| %>
    <div><%= link_to t.title, text_path(t) %></div>
<% end %>

问题是当我点击链接时,它会将我重定向到“/text.1”而不是“/text/1”。谁能弄清楚为什么?

谢谢。

4

2 回答 2

1

听起来文本是您应用程序中的一种资源 - 您应该使用资源路由

对于这种确切的情况,如果由于某种原因您不想使用资源路由,您应该查看您的输出rake routes并查看分配给您的text#show路由的名称并使用它。

于 2012-09-29T03:38:56.203 回答
0
try this 


   <h1>Texts</h1>
    <% @texts.each do |t| %>
       <div><%= link_to t.title, t %></div>
     <% end %>

或这个

   <h1>Texts</h1>
    <% @texts.each do |t| %>
       <div><%= link_to t.title, text_path(:id => t.id) %></div>
     <% end %>
于 2012-09-29T04:41:04.683 回答