Reputation: 378
i am passing reference id as from requirement table in collection_select
but instead of showing team_id as drop-down i want to user as team_name
from team
table by using team_id.
also i want distinct record.
form.html.erb
<div class="field columns large-4">
<%= form.label :team, :class=>"" %>
<%= form.collection_select :requirement_id, @project.requirements, :id, :team_id, prompt: true %>
</div>
Upvotes: 0
Views: 51
Reputation: 47532
Try following, Use delegate in model
In models/requirement.rb
delegate :name, to: :team, prefix: true
or use custom method
def team_name
team ? team.name : 'No team associated'
end
& then value_method
in view
<%= form.collection_select :requirement_id, @project.requirements, :id, :team_name, prompt: true %>
Upvotes: 1