About each What to do It has the function of repeating the contents of the array Example) <% @posts.each do |post| %> posts is the variable name post is the one that puts the contents of the array for the time being < div class = "posts-index-item">
< % = post.content %> There is a situation where only post is good here. This time I am taking an array with Post.all in the terminal (because there is data in the column name content) < /div> <% end %>
To give an example, it became more complicated, but if I wrote each when writing repetitive processing You can write it short.
Recommended Posts