How to create a submit all button for my form_for

依然范特西╮ 提交于 2020-01-17 04:58:30

问题


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>

回答1:


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

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



来源:https://stackoverflow.com/questions/35526734/how-to-create-a-submit-all-button-for-my-form-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!