Guest User

Untitled

a guest
Jun 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // create.js.erb
  2. $("#add_item_form").replaceWith("<%= escape_javascript(render(:partial => 'designs/items_form')) %>");
  3.  
  4.  
  5. // application.js
  6. jQuery.fn.submitAjaxItemForm = function() {
  7. this.submit(function() {
  8. $.post(this.action, $(this).serialize(), null, "script");
  9. return false;
  10. })
  11. return this;
  12. };
  13.  
  14. $(document).ready(function() {
  15. $("#add_item_form").submitAjaxItemForm();
  16. });
  17.  
  18.  
  19. // designs/_items_form.html.erb
  20. <% form_for [@design, @design_component], :html => {:id => "add_item_form" } do |f| %>
  21. <% unless @item_container.blank? -%>
  22. <p class="options-choose" id="item_container_label"><%= @item_container.label %>:</p>
  23. <% end -%>
  24. <% @items.each_with_index do |item, i| -%>
  25. <% line = i % 2 == 1 ? "odd" : "even" -%>
  26. <% content_tag :p, :class => line do %>
  27. <%= radio_button 'design_component', 'item_id', item.id %>
  28. <%= item.label %>
  29. <% end -%>
  30. <% end %>
  31. <%= submit_tag "Next" %>
  32. <p class="options-choose" id="ajax_msg">&nbsp;</p>
  33. <% end %>
Add Comment
Please, Sign In to add comment