Here's what I am trying to achieve:
Group_x.name
member1.name -- member1.join_date -- etc
member2.name -- member2.join_date -- etc
...
Group_y.name
member1.name -- member1.join_date -- etc
member2.name -- member2.join_date -- etc
...
What I'm going for is really very similar to this although the implementation there doesn't work for me.
I've gotten this far in my controller:
def index
# https://stackoverflow.com/a/17835000/2128691
@user_group_ids = current_user.student_groups.map(&:id)
@students = Student.where('student_group_id IN (?)', @user_group_ids)
# https://stackoverflow.com/a/10083791/2128691
@students_by_group = @students.uniq {|s| s.student_group_id}
@title = "All students"
end
and calling the following in my view -
<% @students_by_group.all.each do |x| %>
<p>
<%= "#{x}" %>
</p>
<% end %>
gives me a list of all student
objects. if i call <%= "#{x.name}" %>
or <%= "#{x.created_at}" %>
, etc, I get the correct information, and everything is great.
But now that I have all this information, how can I put the group.name (in my code it would be x.student_group.name
) as a header for all of the students for which that group_name is true?