这是另一种选择,我认为它更像是“轨道”方式:
您应该将其添加到client.rb模型中:
def full_name
first_name + ' ' + last_name
end
,然后在您看来是这样的:
<%= select_tag("clients",options_from_collection_for_select(@clients,"id","full_name"),include_blank: '--SELECT--') %>
,
简单的答案
纯html
<select name="clients">
<option value="1">Thomas Carrier</option>
<option value="2">Michel Carrier</option>
...
</select>
或使用红宝石(https://guides.rubyonrails.org/layouts_and_rendering.html)
<select name="clients">
<% @clients.each do |client| %>
<option value="<%= client.id %>"><%= client.firstName %> <%= client.lastName %></option>
<% end %>
</select>
另请参阅Yaniv Iny的答案,以寻求更好,更正确的方法
本文链接:https://www.f2er.com/3123626.html