Filling form elements using Ajax

Hello folks. I’m starting to Ruby on Rails and I have a doubt about a
very
straightforward application.

Suppose I have a form whose fields are all blank. On this same page, I
have
another form on which I can query for some information from my database.
Is there any nice way on which I can gather the query results and fill
the
first form’s fields with it using AJAX, without having to write handling
functions in Javascript, only using Ruby ?

The closer I got from it was putting the first form inside a

and
call
form_remote_tag function, whose :action parameter was a function that
wrote
all form’s html code again (filling the fields).

I am thinking about writing a function that writes a xml document with
the
results instead of the whole html code for the form, then I would have
just
to write a single javascript function to handle it. But I wonder whether
exists some ellegant way to do it in rails.

Thanks

Felipe

Sure,
but are you sure this is the right way to get what you want?

you can access any DOM element with the page hash.

ex:

html:

RJS:

page[:monkey].value = “likes bananas”

I’ve just solved this problem creating a layout named _form2.rhtml with
the
source code of the first form and writing

render :partial => form2

in the controller, just after retrieving the information I needed. Very
nice
=)

Thank you all.

Felipe