1

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>
marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Ariz
  • 15
  • 2
  • This is basically duplicate of [your own question](http://stackoverflow.com/questions/35526734) with a minor new detail, which you could have clarified in that original post. – David K-J Feb 25 '16 at 13:52
  • Why are you creating a separate form for each `Sheet` object? – jeffdill2 Feb 25 '16 at 19:49

1 Answers1

0

It's not possible to do this with just jquery or javascript because each save will cancel out the previous one. I spent a long time trying to make something exactly like this to work.

I found that using accepts_nested_attributes was a good workaround, although there are other options. Here's an example which also includes a link to RailsCasts #196 that's helpful Rails 4: accepts_nested_attributes_for and mass assignment

Community
  • 1
  • 1
Josh
  • 46
  • 1
  • 10