tanya
tanya

Reputation: 2985

select collection -- displaying more than 1 column value in the select list

I have got the following line of code in my new player.html.erb file.

<% form_for @player, :html => { :multipart => true } do |f| %>

Team: <%=  f.select(:SUB_TEAM, [["--New--", "new"]] + Team.all.collect {|p| [ p.BSR_TEAM_NAME, p.BSR_TEAM_ID  ] }, {:include_blank => 'None', :selected => params[:teamID].to_i}) %>


...
<% end %>

User can associate the player to a team.

Currently for the Team field, a drop down list is displayed with the team names.

Now i need to include the 'team leader name' next to the team name in the drop down list.

I tried the following but it does not seem to work:

Team: <%=  f.select(:SUB_TEAM, [["--New--", "new"]] + Team.all.collect {|p| [ p.BSR_TEAM_NAME -- p.BSR_TEAM_LEADERNAME, p.BSR_TEAM_ID  ] }, {:include_blank => 'None', :selected => params[:teamID].to_i}) %>

I would be grateful if somebody could give me a hint how to display the team lead name next to the team name.

Cheers

Upvotes: 0

Views: 429

Answers (1)

BitOfUniverse
BitOfUniverse

Reputation: 6021

Try this:

Team: <%=  f.select(:SUB_TEAM, [["--New--", "new"]] + Team.all.collect {|p| [ "#{p.BSR_TEAM_NAME} -- #{p.BSR_TEAM_LEADERNAME}", p.BSR_TEAM_ID  ] }, {:include_blank => 'None', :selected => params[:teamID].to_i}) %>

Upvotes: 1

Related Questions