【发布时间】:2014-06-08 12:11:12
【问题描述】:
我有一个 Product 模型和一个 Size 模型。我想以我的简单形式显示每个产品可用尺寸的下拉列表。我想我需要使用 simple_form 提供的关联助手,但我无法让它工作。任何人都可以帮忙吗?谢谢
我得到的错误是:
Association cannot be used in forms not associated with an object
Product.rb
class Product < ActiveRecord::Base
has_many :order_products
has_many :orders, through: :order_products
has_many :sizes
end
大小.rb
class Size < ActiveRecord::Base
belongs_to :product
end
products/show.html.erb
<%= simple_form_for :basket, url: product_basket_path(@product), remote: true do |f| %>
<%= f.input :quantity, as: :select, collection: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], selected: 1, required: false %>
<%= f.association :size %>
<%= f.button :submit, "Add to basket" %>
<% end %>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 simple-form