除了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发布于 2018-05-04 18:27:20
通过添加解决了问题
> parseInt() 敬MaxValue。
https://stackoverflow.com/questions/50162903
复制相似问题