This is Qiita's first post.
Currently, I am creating an EC site with Ruby on Rails. When displaying the product list, the phenomenon that the contents (?) Of params are displayed in a row at the bottom of the view occurred as shown below.
It looks like this at the bottom of the view
#<Item id: 5, title: "Ah ah", artist: "Ah ah", text: "Ah ah", genre_id: 15, country: "JP", format_id: 2, status_id: 2, price: 500, stock: 1, created_at: "2020-09-30 15:55:20", updated_at: "2020-09-30 15:55:20">,# <Item id: 4, title: "Good", artist: "Good", text: "Good", genre_id: 13, country: "JP", format_id: 2, status_id: 2, price: 5000, stock: 1, created_at: "2020-09-30 15:32:51", updated_at: "2020-09-30 15:32:51">,
The following is omitted
#app/views/items/index.html.erb
<%= render "shared/header" %>
<div class="main-wrapper">
<div class="item-wrapper">
<%= @items.each do |item| %>
<div class="item">
<div class="item-image-content">
<%= image_tag item.image, class:"item-image" %>
</div>
<div class="item-format">
<%= item.format.name %>
</div>
<div class="item-artist">
<%= item.artist %>
</div>
<div class="item-title">
<%= item.title %>
</div>
<div class="item-price">
<%= item.price %>Circle(tax included)
</div>
</div>
<% end %>
</div>
</div>
At first I thought I forgot to close the tag, but it seems that it is different.
It was actually a very simple mistake.
<%= @items.each do |item| %>
I equated it with <% =%> even though I didn't actually see it in the view.
<% @items.each do |item| %>
If you remove =, the contents of params that were displayed in a row disappeared. It was a new learning that if you add = to something that is not displayed in the view, this will happen.
Recommended Posts