Reputation: 207
I am trying to implement a dropdown menu to display all the names I have in my database. I tried unsuccessfully the following code:
<%= form_for @airline, remote: true do |f| %>
<%= f.select :name, [@airlines.names] %>
<%= f.submit %>
<% end %>
Controller:
def index
@airlines = Airline.all
@airline = Airline.new
end
I assume the solution is quite straight forward but I couldn't find it.
Upvotes: 0
Views: 101
Reputation: 3699
This should do
<%= f.select(:name, @airlines.collect { |airline| [airline.name,airline.id] }, {:include_blank => 'Choose 1'},:class=>"class_name") %>
Upvotes: 2