ruby - Add one more same set of inputs on click rails -


how can add 1 more same set of inputs example education object, have 2 new education objects after submitting? preferable new set needs shown clicking on icon goes after existing set of inputs.

this new method:

def new   @user = user.new   @user.educations.build   @user.works.build end 

and view it:

<%= simple_form_for [:admin, @user] |u| %>       <%= u.error_notification %>        <%= u.input :name, label: "name" %>       <p><b>photo</b></p>       <%= image_tag(@user.photo_url, size: "80x90",                     class:"img-rounded") if @user.photo? %>       <%= u.input :photo, label: false %>       <%= u.input :tel, label: "tel.:" %>        <h3>education</h3>       <hr>       <%= u.simple_fields_for :educations |e| %>         <%= e.input :name, label: "university" %>         <%= e.input :year_started, label: "started" %>         <%= e.input :year_finished, label: "ended" %>       <% end %>        # icon `+`       <i class="fa fa-plus fa-2x"></i>        <h3>work</h3>       <hr>       <%= u.simple_fields_for :works |w| %>         <%= w.input :name, label: "name" %>         <%= w.input :year_started, label: "started" %>         <%= w.input :year_finished, label: "ended" %>       <% end %>         <%= u.button :submit, "Надіслати" %> <% end %> 

easiest solution cocoon gem - https://github.com/nathanvda/cocoon


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -