0

I have a has_and_belongs_to_many relationship between client "projects" and "features" that they selected through a collection_checkbox administered through a join table called projects_features.

So: each user is able to create projects, and these projects have features that they select and save using a checkbox list - awesome.

I am now trying to edit the show view when the customer wants to take a look at his project, and want to display a list of features his particular project has. How would you do this? Could I do it through a loop displaying from the table or would I need to store the matching features into an array and then display them?

Stephen
  • 187
  • 12

1 Answers1

0

The features are already an attribute of the project, so you can do in the view something like the following...

<h4>Features</h4>

<% @project.features.each do |feature| %>
  <%= feature.name %><br>
<% end %>

This is very simple but you can enhance by using a HTML table or other presentation style.

SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53
  • That works perfectly thank you! Man, still trying to wrap my mind around these associations! Thanks again :) – Stephen Sep 05 '16 at 09:49