2012-09-22 111 views
0

我的新轨道。入门Ruby on Rails的 - 脚手架

当我为用户生成脚手架,在产品/ index.html的我有这样的代码

<h1>Listing users</h1> 

<table> 
    <tr> 
    <th>Name</th> 
    </tr> 

<% @users.each do |user| %> 
    <tr> 
    <td><%=h user.name %></td> 
    <td><%= link_to 'Show', user %></td> 
    <td><%= link_to 'Edit', edit_user_path(user) %></td> 
    <td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td> 
    </tr> 
<% end %> 
</table> 

<br /> 

<%= link_to 'New user', new_user_path %> 

------------------------------------------------------------------------------------------------------------------------------- 

My doubt is in link_to tags, 

<%= link_to 'Show', user %> 
<%= link_to 'Edit', edit_user_path(user) %> 
<%= link_to 'New user', new_user_path %> 

为什么不show_user_path(用户)?对于第一个链接“显示” 任何帮助将apprecated

回答

0

而产生的支架,您所创建的资源“用户”,这就是为什么你可以用它“原样”在link_to:轨知道你想看到的资源使用者。 show_user_path(user)链接到控制器show动作直接。

2

show_user_path会的工作,它只是更详细。

欢迎的Ruby on Rails的魔术。

0

这是Ruby on Rails中约定,你可以使用show_user_path(user)了。