1

If i have this simple block

<% p.sectors.each do |s| %>
  <%= s.name %>
<% end %>

That iterates through all of the sectors , how would i get the results to print out in a comma separated sentence, so something like this

web design, web development, Software testing

There is a method called to_sentence but is that relevant here and how do i apply this method?

Thanks

1
  • I guess you may use <%= p.sectors.map(&:to_sentence).join(', ') %> Commented Jan 10, 2014 at 11:12

2 Answers 2

4
<%= p.sectors.map(&:name).join(", ") %>
Sign up to request clarification or add additional context in comments.

Comments

1
<%= p.sectors.map{|item| item.name}.join(',')%>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.