1

In my app I have form with fields for nested model, it looks like this:

= simple_form_for [:partners, @car], url: wizard_path do |f|
  = f.association :payment_types, as: :check_boxes
  = f.simple_fields_for :prices do |p|
    = p.input :from_days
    = p.input :to_days
    = p.input :netto_price
    = p.input :available_from, as: :string
    = p.input :available_to, as: :string 
  = f.submit

Now I want to have button "Add new" and when I click it it will render through javascript fields for new Price. How can I do it?

1

1 Answer 1

1
  1. Put the form in a partial
  2. make a button <%= link_to new_wizard_path, remote: true %>
  3. create a file in your views/wizards folder new.js.erb
  4. In new.js.erb, do a javascript call to remove the old form re-render the form partial. I would do this with jQuery:

    $('#form-div').html('<%= render 'form %>');

And there you have an Ajax thing. Simple as that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.