限制haml

时间:2017-10-04 17:47:28

标签: ruby-on-rails haml

我在使用RoR进行编码时非常新,我正在使用Haml,因为我正在做一个学校项目,所以我决定尝试一下。问题是我遇到了一个问题。我的对象productoreq_quantity中有一个属性,它是客户端请求的特定产品的数量。在我的视图中,我有一个输入框,供管理员授权客户请求的数量

.col-xs-2
  .text-center
     = product.input :auth_quantity, label: false, required: "required"

我希望将:auth_quantity限制为小于或等于req_quantity,因为目前允许的值大于req_quantity

这是我用Google搜索后的第一个问题,我似乎找不到答案。

2 个答案:

答案 0 :(得分:0)

这就是我在haml中的表现:

.col-xs-2
  .text-center
     = product.input :auth_quantity, type: "number", max: "<%= producto.req_quantity  %>" label: false, required: "required"

其中producto.req_quantity是客户要求的特定产品数量的数值。

答案 1 :(得分:0)

所以我基本上就这样解决了。谢谢你的回答,让我想了很多!!

.col-xs-2 .text-center = producto.input :auth_quantity, input_html: { min: '0', max: product.object.req_quantity, step: 'any' }, label: false, required: "required"