【问题标题】:How to have one form, two submits with different form elements associated with specific submit如何拥有一个表单,两个提交与特定提交相关联的不同表单元素
【发布时间】:2016-07-21 09:20:36
【问题描述】:

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

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

以下是我目前的代码,但我不确定如何继续以及这是否可能;

.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'

【问题讨论】:

    标签: ruby-on-rails forms


    【解决方案1】:

    你可以有不同的提交按钮,像这样:

    在你看来:

    <%= 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
    

    【讨论】:

    • 这两个动作有不同的路径,只有表单中的某些元素与特定路径相关。我怎样才能适应这个?
    猜你喜欢
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 2020-11-03
    • 2016-09-26
    • 1970-01-01
    • 2013-08-31
    • 2014-08-07
    • 1970-01-01
    相关资源
    最近更新 更多