This seems like a somewhat common issue and I'm wondering what the common pitfalls, best practices, best approach, security concerns, etc., are when creating javascript on the server to be later loaded client side.
FWIW, I'm doing this in Ruby and I'm using JQuery as well. It's basically a form builder. Here's what I'm doing:
I have an admin form builder that dynamically creates the static form inputs (eg select, radio, checkboxes, and a couple of more complex inputs as well) I need to create corresponding javascript event handlers (using jquery). I basically have html builder lambdas and event handler lambdas that are mapped to each predefined input type: ie select has something like {'select'=>[select_builder_lamb, select_js_handler_lamb]}
so I can look up the html type and then generate the needed code allowing the administrator to create a form "to their liking". This is working great.
Now I have to figure out whether to serialize this and then reload it when the registration page is requested, write out the javascript to an "unobtrusive" file, or store the raw html and javascript in the database, etc. No problems with the generation itself - so if the high level is: 1) make html & javascript 2) persist for later use 3) use for an http request - my question is for steps 2 and 3.
If you have experience doing this kind of thing and could provide some forwarning and wisdom it would be deeply appreciated!