问题
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