【发布时间】:2018-05-03 19:54:18
【问题描述】:
除了 CurrentMaxValue 为 10 的情况之外,以下 code 工作正常,无论输入值如何,选项都只会给出 10
另一个问题是,尽管 CurrentMaxValue 低于 10,但它仍允许选项 10(当第二个选项框填充不同的值时,第一个默认为剩余数量)
代码在使用 fiddle 时可以正常工作,但是在复制到应用程序时它不起作用。 有什么建议吗?
购物车商品型号
class CreateCartItems < ActiveRecord::Migration[5.2]
def change
create_table :cart_items do |t|
t.references :cart, index: true, foreign_key: true
t.references :train_class, index: true, foreign_key: true
t.references :passenger, index: true, foreign_key: true
t.integer :passenger_qty
t.integer :male
t.integer :female
t.decimal :unit_price
t.decimal :total_price
t.string :outbound
t.timestamps
end
end
查看
<div class="female-male-options">
<div class="female-box">
<%= f.label (t "reservations.female_passengers"), {:class => 'form-container-item-label'} %>
<%= f.select(:female, @travelers, {selected: @travelers_select}, { id: 'female'}) %>
</div>
<div class="male-box">
<%= f.label (t "reservations.male_passengers"), {:class => 'form-container-item-label'} %>
<%= f.select(:male, @travelers, {selected: @travelers_select}, { id: 'male'}) %>
</div>
</div>
它的控制器
class ReservationsController < ApplicationController
def show
...
@travelers = [0,1,2,3,4,5,6,7,8,9,10]
@travelers_select = params[:travelers]
end
end
【问题讨论】:
标签: javascript ruby-on-rails integer html-select