【发布时间】:2014-05-27 07:23:59
【问题描述】:
我有一个表单,它在 select2 下拉框中显示项目,但我还想显示项目的价格并输入将显示总价的数量。使用带有这些附加功能的 select2 gem 会很好,但我不知道该怎么做。
我必须知道选择了哪个项目,然后从表中提取价格。
表格
<%= simple_form_for(@order) do |f| %>
<%= f.error_notification %>
<%= f.input :code %>
<%= f.association :items, collection: Item.all, label_method: :name, value_method: :id, prompt: "Choose an item", input_html: { id: 'item-select2' } %>
<%= f.submit %>
<% end %>
塔布
create_table "items", force: true do |t|
t.string "name"
t.decimal "price"
t.integer "quantity"
t.decimal "discount"
end
create_table "orders", force: true do |t|
t.string "code"
t.integer "user_id"
end
create_table "order_items", force: true do |t|
t.integer "item_id"
t.integer "order_id"
t.integer "quantity"
t.decimal "price"
end
【问题讨论】:
-
你的项目是私有的?或者我可以在github上找到它?
-
很难理解 select2 应该是什么样子。是多选吗?
-
是多选,带搜索的下拉选择框
-
即使没有select2,我该怎么办?