在rails表格中加载模态。自定义条纹表单

时间:2014-10-27 18:39:56

标签: ruby-on-rails forms ruby-on-rails-4 stripe-payments

我试图在rails表单中的模式中加载付款表单。就像现在一样,当我点击"立即购买"模态将加载,但表单将提交。如果有人点击"提交"在模态中。

        = form_tag foo_path, id: 'payment-form' do
      -if @store.products == nil 
        Test
      - @store.products.each_with_index do |product, index|
        .row
          .col-lg-2
            - if current_user
              - if store.user_id == current_user.id
                = link_to "Delete", product_path(product), data: { method: "delete", confirm: "Are you sure?"}
          .col-lg-8
            .panel.panel-default
              .panel-body
                .row
                  .col-lg-2
                    %input{:type => "checkbox", :id => "switchName#{index}", :class => "check"}/
                    %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
                    = 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)
          .col-lg-2
      -if current_user
      -else
        %span.payment-errors
          .text-center
            %h2.total-amount        
              Total:  
              $0.00
          %hr
            .text-center
              %button.btn.btn-primary.btn-lg{"data-target" => "#myModal", "data-toggle" => "modal"}
                Buy Now

1 个答案:

答案 0 :(得分:1)

默认情况下,点击<button>元素时,会提交包含的表单:source

如果您在创建按钮时使用{"data-target" => "#myModal", "data-toggle" => "modal", "type" => "button"},则应显示您的模式而不提交表单。

然后,如果你想要发生的话,你必须处理在你的模式中提交表格。