I am having trouble with my table in ruby. I am allowing a user to search for a class by a prefix or a title, so that sends them to a found_by_prefix or found_by_title page and I need to use the find_all_by_prefix(params[:prefix]). So when I did that I was getting an error so I researched it and found that using <%=@course.map(&:prefix).join(', ')%> would put all the courses found in my table but it only puts all the results in one row. I just want to know how to make 4 rows for the 4 results!
Controller:
def found_by_prefix
@course = Course.find_all_by_prefix(params[:prefix])
end
View:
<table border=1>
<tr><th>id</th><th>prefix</th><th>number</th><th>title</th><th>section</th></tr>
<tr>
<td><%=@course.map(&:id)%></td>
<td><%=@course.map(&:prefix).join(', ')%></td>
<td><%=@course.map(&:number).join(', ')%></td>
<td><%=@course.map(&:title).join(', ')%></td>
<td><%=@course.map(&:section).join(', ')%></td>
</tr>
</table>
Just loop through the results, creating a row for each one:
Also, you should probably name your instance variable
@coursesinstead of@coursebecause it represents a collection, not a single model object.