collection_select method gives error in Rails 3.1.1

前端 未结 1 454
忘了有多久
忘了有多久 2020-12-17 20:22

I have a Model called Category and other Model Product. They have has_many and belongs_to relation. But code in my view

    

<%= f.collection_sel

相关标签:
1条回答
  • 2020-12-17 21:12

    Chances are you have something like this:

    <%= form_for @product do |f| %>
    

    Because f is already tied to product, you don't need to include it as your first argument, so it should just be:

    <%= f.collection_select :category_id, Category.all, :id, :name %>
    

    Or, you could not use f.:

    <%= collection_select :product, :category_id, Category.all, :id, :name %>
    
    0 讨论(0)
提交回复
热议问题