简体   繁体   中英

Rails app create object and render partial with jquery

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM