views:

29

answers:

2

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 ?

+2  A: 

<%= (@products_in_category.map {|x| x.name}).to_sentence %>

Peter
+1  A: 

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
sepp2k
Thnx, Can i make each name to be a link to the product in this way ? or its not possible in this method ?
Datis