[英]Getting Started with Ruby on Rails - Scaffold
我是鐵桿新手。
當我為用戶生成腳手架時,在products / 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(用戶)? 對於第一個鏈接'顯示'任何幫助將得到贊賞
show_user_path可以工作,它只是更詳細。
歡迎來到Ruby on Rails的魔力。
在生成腳手架時,您創建了資源 “user”,這就是您可以在link_to
“按原樣”使用它的原因:rails知道您想要查看資源用戶。 show_user_path(user)
直接鏈接到控制器show action 。
這是Ruby on Rails中的一個約定,你也可以使用show_user_path(user)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.