<%= f_form_for product, remote: true do |f| %> <%= image_tag product.avatar(:small) %> <%= f.text_field :name, skip_label: true %> <%= f.price_field :price, skip_label: true %> <%= f.number_field :stock, skip_label: true %> <%= f.check_box :deleted, skip_label: true %> <%= f.number_field :calories, skip_label: true %> <%= f.button "Update", class: "btn btn-primary" %> <%= javascript_tag do %> var id = "#edit_<%= dom_id(product) %>"; var inputs = $(id).parent().find('input'); $(id).parent().find('button').on('click', function(e) { e.preventDefault(); $(id).append(inputs.clone()); $(id).append(''); $(id).submit(); }); <% end %> <% end %>