# Observe\_field doing nothing

**URL:** <https://www.ruby-forum.com/t/observe-field-doing-nothing/49912>\
**Category:** Rails\
**Created:** [December 10, 2005, 12:53am UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912 "2005-12-10T00:53:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 10, 2005, 12:53am UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/1 "2005-12-10T00:53:03Z")

</div>

Hi

Here’s the code:

\<%= select\_tag “extra”, options\_for\_select(@extra\_fields) %\>

\<% observe\_field “extra”, :update =\> “extra\_fields”,  
:url =\> {:action =\> :new\_edit\_field} %\>

I want to select from the dropdown, and have a controller that  
generates a text field for the option selected and puts it in the  
extra\_fields div.

When I do the select, there is complete silence: webrick does not log  
receipt of a POST, and I have a breakpoint in the new\_edit\_field  
action which is never hit.

Any ideas what I’m doing wrong?

Thanks!

–  
James H.  
Web application developer  
Centre for Health Services and Policy Research  
Vancouver, BC

---

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 10, 2005, 1:05am UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/2 "2005-12-10T01:05:15Z")

</div>

James H. wrote:

> generates a text field for the option selected and puts it in the  
> extra\_fields div.
> 
> When I do the select, there is complete silence: webrick does not log  
> receipt of a POST, and I have a breakpoint in the new\_edit\_field  
> action which is never hit.
> 
> Any ideas what I’m doing wrong?

Did you leave the ‘=’ out of the erb tag for the observe\_field call?

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 10, 2005, 4:41am UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/3 "2005-12-10T04:41:45Z")

</div>

On 12/9/05, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I want to select from the dropdown, and have a controller that  
> > generates a text field for the option selected and puts it in the  
> > extra\_fields div.
> > 
> > When I do the select, there is complete silence: webrick does not log  
> > receipt of a POST, and I have a breakpoint in the new\_edit\_field  
> > action which is never hit.
> > 
> > Any ideas what I’m doing wrong?
> 
> Did you leave the ‘=’ out of the erb tag for the observe\_field call?

I’ve tried it both ways, with the same result. My understanding is  
that the ‘=’ is used for code that is going to dump some output? So it  
would seem that the ‘=’ is not required, but I don’t know for sure.  
jh

–  
James H.  
Web application developer  
Centre for Health Services and Policy Research  
Vancouver, BC

---

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 11, 2005, 11:06pm UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/4 "2005-12-11T23:06:23Z")

</div>

On 12/9/05, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You definitely need the ‘=’, because it has to spit out a script  
> section.

Ah, of course, that makes sense. I’ll put it back, but that’s still  
not my whole problem…as you point out:

> I can see another problem:  
> {:action =\> :new\_edit\_field}  
> should be  
> {:action =\> ‘new\_edit\_field’}
> 
> Actions and controllers needing to be strings rather than symbols  
> is one of Rails’ biggest gotchas. As a newbie I certainly fell  
> prey to it. Is there a good reason for it?

Is it even consistent? I’m not at work right now so I can’t check but  
I seem to recall it working for me some of the time. Nevertheless, I  
also know that I’ve ‘fixed’ things in the past by making this change,  
so, will do.

> If it still doesn’t work, use your browser to check the generated  
> HTML source, and work out what it will do.

## Good plan. Thanks for the Monday morning to-do list 😉 jh

James H.  
Web application developer  
Centre for Health Services and Policy Research  
Vancouver, BC

---

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 10, 2005, 6:52am UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/5 "2005-12-10T06:52:07Z")

</div>

James H. wrote:

> > > \<% observe\_field “extra”, :update =\> “extra\_fields”,  
> > > :url =\> {:action =\> :new\_edit\_field} %\>
> > 
> > Did you leave the ‘=’ out of the erb tag for the observe\_field call?
> 
> I’ve tried it both ways, with the same result. My understanding is  
> that the ‘=’ is used for code that is going to dump some output? So it  
> would seem that the ‘=’ is not required, but I don’t know for sure.

You definitely need the ‘=’, because it has to spit out a script  
section.

I can see another problem:  
{:action =\> :new\_edit\_field}  
should be  
{:action =\> ‘new\_edit\_field’}

Actions and controllers needing to be strings rather than symbols  
is one of Rails’ biggest gotchas. As a newbie I certainly fell  
prey to it. Is there a good reason for it?

If it still doesn’t work, use your browser to check the generated  
HTML source, and work out what it will do.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 12, 2005, 8:04pm UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/6 "2005-12-12T20:04:20Z")

</div>

On 12/9/05, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> prey to it. Is there a good reason for it?
> 
> If it still doesn’t work, use your browser to check the generated  
> HTML source, and work out what it will do.

Here’s is what is being generated:

//

I’ve changed the action from a symbol to a string, with no effect. The  
js code above does not cause a post to be sent to the server on  
selection of an option from the select list. Guess I’ll have to dig  
into the javascript to see what’s going on.

–  
James H.  
Web application developer  
Centre for Health Services and Policy Research  
Vancouver, BC

---

<div class="post-metadata">

**Author:** ![hughes.james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@hughes.james](https://www.ruby-forum.com/u/hughes.james)\
**Post date:** [December 12, 2005, 9:04pm UTC](https://www.ruby-forum.com/t/observe-field-doing-nothing/49912/7 "2005-12-12T21:04:35Z")

</div>

On 12/12/05, James H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 12/9/05, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> //]]\>
> 
> I’ve changed the action from a symbol to a string, with no effect. The  
> js code above does not cause a post to be sent to the server on  
> selection of an option from the select list. Guess I’ll have to dig  
> into the javascript to see what’s going on.

Ok, found the problem. My prototype.js was dangerously out of date. It  
didn’t even have the EventObserver function in it. Puzzling as to why  
no javascript error was being reported though.

thanks,  
jh

–  
James H.  
Web application developer  
Centre for Health Services and Policy Research  
Vancouver, BC
