Ruby on Rails Saturday, October 29, 2011

On Sat, Oct 29, 2011 at 05:49, Jedrin <jrubiando@gmail.com> wrote:

> I would like to consider if I can load the form in pieces via AJAX.

The big question is, can you group the elements so that they are from
a simpler batch of database queries? It sounds like many of the form
elements, if not all of them, would be coming from the same rather
complex database query. If so, then I would recommend you take these
elements all together in one AJAX call, so that the database query is
only done once.

Very simple example:

Suppose your form has a customer's name, contact information, and
order history, including the details of each order (how many of what
at what price each, total, tax, shipping, grand total), and the master
total of all orders. The name and order *IDs* could come from two
very simple queries done in the controller. Then you could have the
form, upon loading in the browser, fire off AJAX queries, one for each
order to get the details. (Better yet, do it not on load, but on user
request, if it's something they don't necessarily always need.) Upon
receiving each of these you could fill in the sections, and add to the
master total. Thus the order detail retrieval would be parallelized.

This probably wouldn't really be worth it, but if your situation is
much hairier, something analogous may be applicable.

Alternately, think about breaking up your form.

-Dave

--
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment