Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 单个表单的多个表单提交按钮rails 4_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 单个表单的多个表单提交按钮rails 4

Ruby on rails 4 单个表单的多个表单提交按钮rails 4,ruby-on-rails-4,Ruby On Rails 4,我正在尝试创建一个表单,该表单允许我删除检查的多个帖子,或者执行其他操作。我正在努力从表单访问post ID。如果我使用f.submit标记,那么我的代码就可以正常工作。但是,当我尝试使用引导按钮时,它将不起作用 下面是视图,它有一个位于引导表内部的表单,然后是表外部的提交按钮 <%= form_for :pending_forms, html: {method: 'get'} do |f| %> <table class="tabl

我正在尝试创建一个表单,该表单允许我删除检查的多个帖子,或者执行其他操作。我正在努力从表单访问post ID。如果我使用f.submit标记,那么我的代码就可以正常工作。但是,当我尝试使用引导按钮时,它将不起作用

下面是视图,它有一个位于引导表内部的表单,然后是表外部的提交按钮

         <%= form_for :pending_forms, html: {method: 'get'} do |f| %>
             <table class="table">
                <tbody>
                    <% if @pending_posts.any? %>
                            <% @pending_posts.each do |post| %>
                                <tr>
                                    <td><%= post.post_name %></td>
                                    <td><%= post.created_at %></td>
                                    <td><%= check_box_tag 'post_ids[]', post.id %></td>
                                </tr>
                            <% end %>
                    <% end %>
                </tbody>
            </table>
            <button type="submit" class="btn btn-danger">Remove Post</button>
            <button type="submit" class="btn btn-primary">Go Live</button>  
        <% end %>
最好在表单标签范围内编写提交按钮

<%= form_tag do %>
  <table>
    <tbody>
       <% if @pending_posts.any? %>
          <% @pending_posts.each do |post| %>
            <tr>
               <td><%= post.post_name %></td>
               <td><%= post.created_at %></td>
               <td><%= check_box_tag 'post_ids[]', post.id %></td>
            </tr>
          <% end %>
       <% end %>
    </tbody>
  </table>
  <button type="submit" class="btn btn-danger">Remove Post</button>
  <button type="submit" class="btn btn-primary">Go Live</button>  
<% end %>

这并不能解决我的问题。这仍然无法删除控制器中选定的帖子。您应该写入PendingPost.whereid:params[:post\u ID]。销毁所有帖子,而不是PendingPost.whereid:params[:commit]。销毁所有帖子,但是,当我单击“删除”时,当我的路由设置为接收GET时,它将发送帖子。您可以显式地告诉form_标记它是GET请求,或者将您的路由更改为在routes中发布。rb文件我编辑了视图,以显示我如何显式地告诉form_标记它是GET。然而,当我试图删除帖子时,这仍然不起作用。我还更新了控制器
<%= form_tag do %>
  <table>
    <tbody>
       <% if @pending_posts.any? %>
          <% @pending_posts.each do |post| %>
            <tr>
               <td><%= post.post_name %></td>
               <td><%= post.created_at %></td>
               <td><%= check_box_tag 'post_ids[]', post.id %></td>
            </tr>
          <% end %>
       <% end %>
    </tbody>
  </table>
  <button type="submit" class="btn btn-danger">Remove Post</button>
  <button type="submit" class="btn btn-primary">Go Live</button>  
<% end %>