I'm new to rails. What I want to do is, assuming that there is a table like the image, I want to divide it into groups for each team and get the values ​​of team A and team B.

On the controller

@team = Team.group ("team"). count

view is

<% @team .each do | c |%>
<span><% = c%></span>
<% end%>

Is written. Of course, I'm using .count, so
["Team A", 3]
["Team B", 2]
However, it is said that it cannot be used only with .group, so I have added .count for the time being, but I want to output only Team A and Team B.
Is there any way? Thank you.

  • Answer # 1

    Simply,Team.distinct.pluck (: team)Is it no good?

Related articles