Ruby on Rails: 显示页面显示错误
Ruby on Rails: show page show something wrong
这是我的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">]
更改此行
<%= @category.soups.each do |soup| %>
到
<% @category.soups.each do |soup| %>
<% %>
-----> 执行语句。
<%= %>
----> 打印输出。
您在遍历 @category 的汤时添加了“=”符号。这样做
<ul>
<% @category.soups.each do |soup| %>
<li>
<%= link_to soup.name , soup %>
</li>
<% end %>
</ul>
这是我的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">]
更改此行
<%= @category.soups.each do |soup| %>
到
<% @category.soups.each do |soup| %>
<% %>
-----> 执行语句。<%= %>
----> 打印输出。
您在遍历 @category 的汤时添加了“=”符号。这样做
<ul>
<% @category.soups.each do |soup| %>
<li>
<%= link_to soup.name , soup %>
</li>
<% end %>
</ul>