使用jquery检查rails对象

Using jquery to check a rails object

本文关键字:对象 rails 检查 jquery 使用      更新时间:2023-09-26

因此,我不希望jquery在检查某个项目后执行某些操作。但这个项目可能不一定在那里,如果它不在那里,那么它就什么都不做。

这就是呈现复选框的位置:

.row
          .col-lg-2
            %input{:type => "checkbox", :id => "switchName#{index}", :class => "check", :name => "switchName#{index}", "data-cost-per-unit" => product.cost_in_cents}/
            %label{:for => "switchName#{index}"}
          .col-lg-8
            = hidden_field_tag("order_products[][product_id]", product.id)
            = product.name
            %br
            .subheader= number_to_currency(product.cost_in_cents.to_f / 100)
          .col-lg-2
            -if product.product_type == "Subscription Based"
            -else
              = select_tag("order_products[][quanity]", options_for_select([0,1,2,3,4,5,7,8,9,10,11,12,13,14,15]), "data-cost-per-unit" => product.cost_in_cents, id: product.name, class: "drop", :prodindex => index)

所以基本上,我希望它将一些东西呈现到一个没有显示的类中,如果product.product_type == "Subscription Based"和Is当前处于选中状态。

我不确定这是否是你的意思:

        -if product.product_type != "Subscription Based"
          = select_tag("order_products[][quanity]", options_for_select([0,1,2,3,4,5,7,8,9,10,11,12,13,14,15]), "data-cost-per-unit" => product.cost_in_cents, id: product.name, class: "drop", :prodindex => index)

但这将与您所拥有的相当,并将为您保存一个else语句