Ruby on Rails:显示页面显示错误

时间:2015-07-22 18:10:05

标签: ruby-on-rails ruby-on-rails-4 erb

这是我的 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>

然而,结果如下。 enter image description here

为什么显示

[#<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">]

2 个答案:

答案 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>