首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Rails j查询section_tag当前值未重置为缺省值

Rails j查询section_tag当前值未重置为缺省值
EN

Stack Overflow用户
提问于 2018-05-04 03:54:18
回答 1查看 25关注 0票数 0

除了CurrentMaxValue为10的情况外,以下code运行正常。无论输入值如何,选项都只会给出10

另一个问题是,尽管CurrentMaxValue低于10,但它仍允许选择10 (当第二个选项框填充不同的值时,第一个选项框将默认为剩余数量)。

代码在使用fiddle时可以正常工作,但在复制到应用程序中时却无法正常工作。有什么建议吗?

购物车项目模型

代码语言:javascript
运行
复制
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

视图

代码语言:javascript
运行
复制
<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>

它的控制器

代码语言:javascript
运行
复制
class ReservationsController < ApplicationController
  def show
    ...
    @travelers = [0,1,2,3,4,5,6,7,8,9,10]
    @travelers_select = params[:travelers]
  end
end
EN

回答 1

Stack Overflow用户

发布于 2018-05-04 18:27:20

通过添加解决了问题

代码语言:javascript
运行
复制
> parseInt() 

敬MaxValue。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50162903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档