2

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>
zishe
  • 10,665
  • 12
  • 64
  • 103
  • Do you have a model named Provider? – Joel Brewer Aug 31 '14 at 21:10
  • Yes. I have a whole mvc for provider that references to categories. – alfonsopintos Aug 31 '14 at 21:12
  • The first error is because you have Providers instead of Provider. What are the relationships you have between your models? – Joel Brewer Aug 31 '14 at 21:16
  • A bill: belongs_to :category belongs_to :user belongs_to :provider has_many :reminders ------ A category: has_many :bills has_many :providers ------- A Provider: belongs_to :category belongs_to :bill – alfonsopintos Aug 31 '14 at 21:18
  • It returns the error "undefined method provider_id for #<#:0x007fd6d53c4728>" A little different than the other error. this one refers to class and not bill like the previous one. – alfonsopintos Aug 31 '14 at 21:28

1 Answers1

1

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>
Joel Brewer
  • 1,622
  • 19
  • 30
  • That returns the first of the two error "uninitialized constant ActionView::CompiledTemplates::Providers" and if i change it to 'Provider.order', it returns "undefined method `merge' for :name:Symbol" – alfonsopintos Aug 31 '14 at 21:34
  • See edit. Try removing "f.", per this answer: http://stackoverflow.com/questions/8147069/collection-select-method-gives-error-in-rails-3-1-1 – Joel Brewer Aug 31 '14 at 21:39