# Observe\_field, does this generate HTML?

**URL:** <https://www.ruby-forum.com/t/observe-field-does-this-generate-html/109437>\
**Category:** Rails\
**Created:** [July 14, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/observe-field-does-this-generate-html/109437 "2007-07-14T23:39:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcampbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@mcampbell](https://www.ruby-forum.com/u/mcampbell)\
**Post date:** [July 14, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/observe-field-does-this-generate-html/109437/1 "2007-07-14T23:39:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mcampbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@mcampbell](https://www.ruby-forum.com/u/mcampbell)\
**Post date:** [July 14, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/observe-field-does-this-generate-html/109437/2 "2007-07-14T23:50:35Z")

</div>

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/](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![mcampbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@mcampbell](https://www.ruby-forum.com/u/mcampbell)\
**Post date:** [July 15, 2007, 12:23am UTC](https://www.ruby-forum.com/t/observe-field-does-this-generate-html/109437/3 "2007-07-15T00:23:04Z")

</div>

I know form\_remote\_for generates HTML, of course 🙂 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.

---

<div class="post-metadata">

**Author:** ![mcampbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@mcampbell](https://www.ruby-forum.com/u/mcampbell)\
**Post date:** [July 19, 2007, 6:07am UTC](https://www.ruby-forum.com/t/observe-field-does-this-generate-html/109437/4 "2007-07-19T06:07:26Z")

</div>

observe\_field and observe\_form both generate SCRIPT elements  
containing that Javascript.

On Jul 14, 3:23 pm, Michael C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
