Search code examples
rubyruby-on-rails-3.1ujs

Populate form using AJAX in Rails 3


I'm new to rails and would like to use AJAX to update the a form's text fields after a value has been placed into a key text field.

I see it's possible to create an event handler using something like:

:onchange => remote_function(...)

but this doesn't feel like it gels with the concept of UJS. Is there another way I can populate the fields in place and delay creating the record until the Submit button is pressed?


Solution

  • Attach a blur/change/whichever you want handler on the text field in question.

    Make the Ajax request, send JSON back, populate the fields as appropriate.