Skip to content

Instantly share code, notes, and snippets.

@brijeshgpt7
Created June 6, 2015 05:49
Show Gist options
  • Save brijeshgpt7/49ecc9d658e1435219e6 to your computer and use it in GitHub Desktop.
Save brijeshgpt7/49ecc9d658e1435219e6 to your computer and use it in GitHub Desktop.
nested form
http://www.amooma.de/screencasts/2015-01-22-nested_forms-rails-4.2/
@brijeshgpt7
Copy link
Author

<script> $('#file_<%=image%>').on('change', function () { var filename = $('#file_<%=image%>').val(); alert($('#image<%=image%>').serialize()); $.ajax({ type: 'POST', beforeSend: function (xhr) { xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')) }, url: '/listings/document', data: $('#image<%=image%>').serialize(), success: function (data) { $("#img-uploaded").html(data); } }); }); ``` </script>

@brijeshgpt7
Copy link
Author

Edit image

              <li> 
               </li>
         
        </ul>
      </div>
      <div class="weblinks">
        <div><span><label>Edit Youtube</label></span>&nbsp;&nbsp;<span>
        <%=text_field_tag :web_link%><a href="#"><i class="fa fa-youtube-play"></i></a></span></div>
        <div><span><label>Edit Youtube</label></span>&nbsp;&nbsp;<span>
        <%=text_field_tag :web_link%><a href="#"><i class="fa fa-globe"></i></a></span></div>
      </div>
    </div>
    <div class="imageanddocument-right">
      <h4>Lorem Ipsum is simply dummy text</h4>
      <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
      <%= form_for Document.new ,:url => document_upload_listings_path, :html => { :id => "image",:multipart => true } do |form| %>
                  <%= form.file_field :avatar,multiple: true %>
                  <%= form.hidden_field :listing_id , :value => @list.id %>
                  <%#= form.submit("Save") %>
                  <%= form.submit "Save", id: "button_id" %>
    
                 <% end %>
    </div>
    

Edit Document

              <li>
                
              </li>
         
        </ul>
      </div>
      <div class="edit-actions">
        <button class="cancel-button" type="button">Cancel</button>
        <button class="save-button" type="button" id="myButton">Save</button>
      </div>
    </div>
    <div class="imageanddocument-right">
      <h4>Lorem Ipsum is simply dummy text</h4>
      <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
    <%= form_for Document.new ,:url => document_upload_listings_path, :html => { :id=>"document",:multipart => true } do |form| %>
                  <%= form.file_field :avatar,multiple: true %>
                  <%= form.hidden_field :listing_id , :value => @list.id %>
                 <%= form.submit "Save", id: "doc_button_id" %>
                 <% end %>
    </div>
    
<script type="text/javascript"> $(document).ready(function() { $('#button_id').hide(); $('#doc_button_id').hide(); $("#myButton").click(function() { $("#image").submit(); $("#document").submit(); }); }); </script>

@brijeshgpt7
Copy link
Author

<img src="<%= asset_path File.extname(image.avatar_file_name)== ".pdf" ? "pdf.png" %>" >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment