这是我的 show.html.erb
<h1> <%= @category.name %> </h1>
<ul>
<%= @category.soups.each do |soup| %>
<li>
<%= link_to soup.name , soup %>
</li>
<% end %>
</ul>
<p> <%= link_to "back", categories_path %></p>
为什么显示
[#<Soup id: 1, name: "Tonkotsu", featured: true, category_id: 1, created_at: "2015-07-22 11:30:37", updated_at: "2015-07-22 16:59:20">, #<Soup id: 4, name: "Beef Flavor", featured: nil, category_id: 1, created_at: "2015-07-22 17:03:34", updated_at: "2015-07-22 17:10:36">]
答案 0 :(得分:1)
更改此行
<%= @category.soups.each do |soup| %>
到
<% @category.soups.each do |soup| %>
<% %>
-----&gt;执行声明。<%= %>
----&gt;打印输出。答案 1 :(得分:1)
你有&#34; =&#34;在遍历@category的汤时附加标志。这样做
<ul>
<% @category.soups.each do |soup| %>
<li>
<%= link_to soup.name , soup %>
</li>
<% end %>
</ul>