I want to use to_sentence method on the block of code to return the names with , separated :
<% @products_in_category.each do |pic| %>
<%= pic.name %>
<% end %>
How can I do this ?
I want to use to_sentence method on the block of code to return the names with , separated :
<% @products_in_category.each do |pic| %>
<%= pic.name %>
<% end %>
How can I do this ?
Replace each with map and it will return an array with the results of invoking the block on each element. So you can do
@products_in_category.map(&:name).to_sentence