observe_field, does this generate HTML?

Michael Chow wrote:

I don't have Rails installed at the moment, I'd like to check myself,
but it's just a simple curiosity.

Install Rails, Firefox, & Firebug, and try it.

observe_field fits into replacement tags <%= %>, which caught my
attention because as far as I know it's just javascript observing a
field and should not stick anything into HTML. Is <%= merely used as an
enabling method, or will there actually be some sort of HTML object
there?

When I use a <%= form_remote_for ... %>, and when I run my site in Firefox, point my mouse to the form, and get the "Context Menu" (the "right" mouse button), Firebug has a feature "inspect element". This shows the form in a panel of my browser, like this:

<form onsubmit="new Ajax.Request('/ring/set_attack_mode', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" method="post" id="attack_form" action="/ring/set_attack_mode">

The <%%> part turned into a big splatch of JavaScript, calling the Prototype.js (or Scriptaculous?) method Ajax.Request. And that hides all the ugly magic required to send the ajax commands to my controller 'ring', action 'set_attack_mode'.

The observe_field stuff must work the same general way - a Rails method, in Ruby, wrapping a Scriptaculous method, in JavaScript.

Also, does the observer have to come after the field it is observing or
can I stick them all at the top of the HTML?

Put them near their observers, so they are clear to read.

observe_field and observe_form both generate SCRIPT elements
containing that Javascript.