user2573222
user2573222

Reputation: 207

Rails 4 dropdown menu pulling from database

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

Answers (1)

Nithin
Nithin

Reputation: 3699

This should do

<%= f.select(:name, @airlines.collect { |airline| [airline.name,airline.id] }, {:include_blank => 'Choose 1'},:class=>"class_name") %>

Upvotes: 2

Related Questions