0

I have a page in my app where I'm using a button_to or button_to_function where a user can add a row to a table. Each row of the table is a data object from the Event model.

When a user clicks "Add Event" button, it should create a new Event object and render a row in the table which is a few drop downs that correspond to the fields in the event object. I will then be using best_in_place for in place editing to modify these fields.

What's the best approach to use jquery to create a new Event object and append a row onto the table which has form fields that correspond to the newly created event object? I'm thinking a call to a controller action which creates the object and renders a partial, but not sure how to do this specifically.

1
  • I think your thought is correct. You should send a request to controller to render a partial which is in .js.erb extension. The javascript inside this file will be executed. In the .js.erb file, you can use jQuery to add the row as html. Commented Sep 2, 2012 at 7:45

1 Answer 1

1

Have a look at Railscast #136 - http://railscasts.com/episodes/136-jquery

It should get you headed in the right direction. Essentially your controller needs to respond to Javascript and then have a js template that will do what you want on the page when received by the browser.

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.