alfonsopintos
alfonsopintos

Reputation: 35

Cant add a second dropdown in my form

I am trying to add a second dropdown menu to a form in my app. I have copied the code from the first drop down and changed the values to match the class I am trying to pull values from. When I remove the second drop down, the app runs smoothly, it is the second menu that returns an error.

uninitialized constant ActionView::CompiledTemplates::Providers

If i change 'Providers.order' to 'Provider.order' in my code, it returns this error:

undefined method `provider_id' for #<Bill:0x007fbf62544ee8>

Here is my code in the form:

  <div class="field">
    <!-- Drop Down menu for categories -->
    <%= f.label :category_id %><br>
    <%= f.collection_select :category_id, Category.order(:name), :id, :name%>
  </div>

  <div class="field">
    <!-- Drop Down menu for providers -->
    <%= f.label :provider_id %><br>
    <%= f.collection_select :provider_id, Providers.order(:name), :id, :name%>
  </div>

Upvotes: 2

Views: 57

Answers (1)

Joel Brewer
Joel Brewer

Reputation: 1652

Try this:

<div class="field">
  <!-- Drop Down menu for providers -->
  <%= label :provider %><br>
  <%= collection_select :provider, :provider_id, Provider.order(:name).all, :id, :name%>
</div>

Upvotes: 1

Related Questions