如何使用一个表单,两个提交具有与特定提交相关联的不同表单元素

时间:2016-07-21 09:20:36

标签: ruby-on-rails forms

我有一个允许用户拒绝或批准记录的表单。我试图设计它,因此有一个拒绝复选框和一个复选框,用于批准每一行。在底部有两个按钮拒绝和批准再次。当用户检查批准一个并拒绝另一个,然后按下其中一个按钮拒绝或批准

我最初希望能够有一个按钮进程,它会知道何时被批准的记录是否会将其传递给批准路径,如果选择拒绝路径,它也会知道将这些值传递给拒绝路径。

以下是我的代码到目前为止,但我不知道如何继续,这是否可能;

.block-body
  %table.table.table-striped.sla
    %thead
      %tr.medium
        %th Campaign
        %th Status
        %th Approve
        %th Reject
        %th.notes{:style => "display: none"} Rejection Reason (Required)
    %tbody
      = form_for :campaign do |f|
        - if @campaigns == nil
          = @campaigns.inspect
        - else
          - @campaigns.each do |campaign|
            %tr.medium
              %td= campaign.name
              %td= campaign.status              
              %td
                -if ["New", "Updated"].include? campaign.status  #-if campaign.status != "Approved"
                  = f.check_box :status, {id: "#{campaign.id}", :class => "approvedservices"}, "Approved"
              %td{:style => "width:100px;"}
                -unless ["Rejected", "Approved"].include? campaign.status
                  = f.check_box :status, {id: "reject#{campaign.id}", :class => "rejectedservices"}, "Rejected"
              %td.notes{:style => "display: none"}
                %input{:style => "display: none", :id => "notesrow_#{campaign.id}", :type => "text"}

          %tr.medium
            %td.white{:colspan => 2}
            %td.white{:style => "width:100px;"}
              = submit_tag "First Button", :name => 'first_button'
            %td.white{:style => "width:100px;"}
              = submit_tag "Second Button", :name => 'second_button'

1 个答案:

答案 0 :(得分:0)

您可以使用不同的提交按钮:

在您看来:

<%= submit_tag t('approve'), name: :commit %>
<%= submit_tag t('reject'), name: :reject %>

在你的控制器中:

def create
  do_something if params[:reject] and return
  do_something_else
end