Forum: Ruby on Rails observe_field, does this generate HTML?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7b9848f7452ca6a1f681e68370577b1c?d=identicon&s=25 Michael Chow (nanostuff)
on 2007-07-14 23:39
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.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-07-14 23:50
(Received via mailing list)
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.

--
  Phlip
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax
7b9848f7452ca6a1f681e68370577b1c?d=identicon&s=25 Michael Chow (nanostuff)
on 2007-07-15 00:23
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.
Fc52ff7ea7bc17530188922f346d4b04?d=identicon&s=25 mboeh@desperance.net (Guest)
on 2007-07-19 06:07
(Received via mailing list)
observe_field and observe_form both generate SCRIPT elements
containing that Javascript.

On Jul 14, 3:23 pm, Michael Chow <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.