Observe_field, does this generate HTML?

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

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?

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?

Thanks.

Michael C. 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:

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.


Phlip
http://www.oreilly.com/catalog/9780596510657/
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax

I know form_remote_for generates HTML, of course :slight_smile: That’s implied
considering there’s a form to be generated. I was asking specifically
about observe_field and observe_form considering they go into a <%= tag
yet there’s no apparent HTML that should be generated.

I was just looking for a quick answer from someone who already used the
helper, I can certainly check myself later, no biggie.

observe_field and observe_form both generate SCRIPT elements
containing that Javascript.

On Jul 14, 3:23 pm, Michael C. [email protected]