Getting data from Rails to Javascript

This started when I upgraded to Rails 2.1. My “roll you own” in place
editor broke because they need the authentication token.

What I did before was I wrapped the editor in a span of a particular
class. In the span, I add an options attribute and a url attribute.
When the page loaded, the on load hook would find the spans of that
class and use the options and url as part of the in place editor
customization. This almost completely separated the html from the
javascript.

But another related event is during some recent debugging, I passed my
pages through the HTML validator and it doesn’t like these options and
url attributes stuck in a span. And, in general, I need more power than
what I have.

So, one thought I had was to have a hash, lets call it
javascript_objects. As the render code executed, it would add things to
this hash. Then the last thing in the layout would be to dump this hash
out as a JSON object in a script tag. It would be wrapped with
something like pageOptions and would create a javascript hash (object).
Details left to the reader.

The pre-written javascript code would look in this pageOptions object
for the options for each of the in placed editors, or whatever other
variable data that Rails knows but is not fixed.

I figure, like all my other ideas in this area, this isn’t a new idea.
Has this been done? Are there other trends of solving the general issue
of how to get Rails knowledge to the javascript code? e.g. what URL do
you post?