如何为我的form_for创建所有提交按钮 [英] How to create a submit all button for my form_for

查看:87
本文介绍了如何为我的form_for创建所有提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ruby on Rails的新手.当我单击link_to "save"时,如何同时提交所有表单.谢谢您的回答.这是我的视图文件的一小段.我想用一个按钮同时保存表格.

I am new to Ruby on Rails. How can I make my form for submit all at the same time when I click the link_to "save". Thank you for your answers. This is a snippet of my view file. I would like to save form for at the same time with one button.

  <% @sheets.each do |getsheets| %>
      <%= image_tag "sheets/#{getsheets.sheetimage.split('/')[-2]}/#{getsheets.sheetimage.split('/')[-1]}" %>
      <div>

        <%= form_for getsheets , :url => sheet_attachment_path(getsheets.sheetid,getsheets.sheetid) do |f| %>

          <%= f.label :"Name: " %>
          <%= f.text_field :name %>

          <%= f.hidden_field :sheetid, :value => getsheets.sheetid %>
          <%= f.hidden_field :projectid, :value => getsheets.projectid %>
          <%= f.hidden_field :sheetimage, :value => getsheets.sheetimage %>

        <% end %>

        <%= link_to "Destroy Sheet", delete_sheet_path(getsheets.sheetid,params[:attachmentid]) %>

      </div>
      <br>
  <% end %>
  <div>

    <%= link_to "Save", "#"%>

    <%= link_to "Cancel",  :controller => "sheet_attachments", :action => "cancel", :attachmentid => params[:attachmentid] %>
  </div>

推荐答案

如果我理解正确,则需要将<%= link_to "Save", "#"%>放入循环中,并为每个对象显示表单.

If I understand you right, you need to put <%= link_to "Save", "#"%> in the loop, and show form for each object.

您需要了解,默认情况下,销毁"按钮会将您重定向到index,这意味着您需要对它进行存根

You need to understand, that destroy button will redirect you to index by default, that mean that you need to stub it

这篇关于如何为我的form_for创建所有提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆