# Strange observe\_field/partial functioning

**URL:** <https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417>\
**Category:** Rails\
**Created:** [October 8, 2008, 11:21am UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417 "2008-10-08T11:21:17Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 11:21am UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/1 "2008-10-08T11:21:17Z")

</div>

Hi I hava a page where there is two combo box displayed and one updates  
the other and it uses observe\_field and partials. The page is not the  
index page so its link is [http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking). But  
while designing I started off without the index page so I directly typed  
the above link to test. But now I am keeping the index page and linking  
this page from index with link\_to. The strange thing is, if I still  
directly type the above link and test, the update thing works great but  
if I first open the index page and then go to this page from there, the  
update doesn’t work at all. So, please help me figure out where I did  
wrong, I just couldn’t seem to figure out…Heres the code:

# IN CONTROLLER (user\_controller.rb)

class UserController \< ApplicationController  
def index  
end

def online\_booking  
end

# def update\_campsites @resultset=[] @result = Campsite.find\_by\_sql("select \* from campsites where walk\_id = "+params[“id”]) for results in @result @resultset \<\< [results.camp\_location, results.camp\_location] end render :partial =\> ‘campsites’, :layout =\> false end

# IN VIEW (online\_booking.rhtml)

Locations  
 \<%= select(:selected, :location, Greatwalk.find\_available\_locations, {:prompt=\>'Select Great Walk Location'}, :id =\> :great\_walks) %\>

 \<%= observe\_field("great\_walks", :url =\> {:controller =\> "user", :action =\> "update\_campsites"}, :update =\> "campsites\_list", :with =\> "id")%\>

Campgrounds   
 \<%= select("selected","campsites", %w{ -- }, :class =\> "select\_campsites") %\>

 \<%=button\_to "Add to Cart", :action =\> :add\_to\_cart, :id =\> "campsites"%\> ================================================================================
# IN PARTIAL (\_campsites.rhtml)

Campgrounds  
 \<%=select "selected", "campsite", @resultset %\>

================================================================================
# IN VIEW (index.rhtml)

# … \<%=link\_to(“Fraser Island”, :action=\>“online\_booking”)%\> …

In the above online\_booking.rhtml Greatwalk is a model where there is a  
method find\_available\_locations.

Any suggestions… thank you.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 1:58pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/2 "2008-10-08T13:58:55Z")

</div>

Frederick C. wrote:

> On 8 Oct 2008, at 10:21, Jay P. wrote:
> 
> > this page from index with link\_to. The strange thing is, if I still  
> > directly type the above link and test, the update thing works great  
> > but  
> > if I first open the index page and then go to this page from there,  
> > the  
> > update doesn’t work at all. So, please help me figure out where I did  
> > wrong, I just couldn’t seem to figure out..Heres the code:
> 
> What do you mean by doesn’t work at all? What happens ?
> 
> Fred

thanks for the reply Fred.. the second combo box doesn’t get updated.  
neither any error is shown it happens like as if nothing is set to the  
first combo box and just filled with some values which in fact is not  
true as observe\_field is set to update the second combo box..

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 12:22pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/3 "2008-10-08T12:22:13Z")

</div>

On 8 Oct 2008, at 10:21, Jay P. wrote:

> this page from index with link\_to. The strange thing is, if I still  
> directly type the above link and test, the update thing works great  
> but  
> if I first open the index page and then go to this page from there,  
> the  
> update doesn’t work at all. So, please help me figure out where I did  
> wrong, I just couldn’t seem to figure out..Heres the code:

What do you mean by doesn’t work at all? What happens ?

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/4 "2008-10-08T14:12:39Z")

</div>

On Oct 8, 12:58 pm, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Frederick C. wrote:
> 
> > On 8 Oct 2008, at 10:21, Jay P. wrote:

> thanks for the reply Fred.. the second combo box doesn’t get updated.  
> neither any error is shown it happens like as if nothing is set to the  
> first combo box and just filled with some values which in fact is not  
> true as observe\_field is set to update the second combo box.

Is it actually making an appropriate ajax request ?

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 2:32pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/5 "2008-10-08T14:32:54Z")

</div>

Frederick C. wrote:

> On Oct 8, 12:58ï¿½pm, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Frederick C. wrote:
> > 
> > > On 8 Oct 2008, at 10:21, Jay P. wrote:
> 
> > thanks for the reply Fred.. the second combo box doesn’t get updated.  
> > neither any error is shown it happens like as if nothing is set to the  
> > first combo box and just filled with some values which in fact is not  
> > true as observe\_field is set to update the second combo box.
> 
> Is it actually making an appropriate ajax request ?
> 
> Fred

ya.. as i said if i directly type in the url to the action which is  
[http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking) then it works but if i open  
the index page first which will be [http://localhost/user](http://localhost/user) and open the  
page where these combo boxes are with a link in the index page, its then  
when the second combo box stops getting updated. thnx

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/6 "2008-10-08T14:46:41Z")

</div>

On 8 Oct 2008, at 13:32, Jay P. wrote:

> > > neither any error is shown it happens like as if nothing is set to  
> > > [http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking) then it works but if i open  
> > > the index page first which will be [http://localhost/user](http://localhost/user) and open the  
> > > page where these combo boxes are with a link in the index page, its  
> > > then  
> > > when the second combo box stops getting updated. thnx

What I’m trying to get you to pinpoint is where it breaks when it  
breaks, or to put it another way, does it fail because:

- changing the combo box doesn’t fire an ajax request
- changing the combo box fires an ajax request with incorrect parameters
- the controller screws something up
- the page does the wrong thing with the response from the controller

Your first step has to be to identify which of the above are happening  
(use firebug etc… to see what is happening)

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/7 "2008-10-08T15:46:16Z")

</div>

Frederick C. wrote:

> On 8 Oct 2008, at 13:32, Jay P. wrote:
> 
> > > > neither any error is shown it happens like as if nothing is set to  
> > > > [http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking) then it works but if i open  
> > > > the index page first which will be [http://localhost/user](http://localhost/user) and open the  
> > > > page where these combo boxes are with a link in the index page, its  
> > > > then  
> > > > when the second combo box stops getting updated. thnx
> 
> What I’m trying to get you to pinpoint is where it breaks when it  
> breaks, or to put it another way, does it fail because:
> 
> - changing the combo box doesn’t fire an ajax request
> - changing the combo box fires an ajax request with incorrect parameters
> - the controller screws something up
> - the page does the wrong thing with the response from the controller
> 
> Your first step has to be to identify which of the above are happening  
> (use firebug etc… to see what is happening)
> 
> Fred

I’m using aptana studio for this and i’m using aptana browser where at  
least after doing something the updating thing works but when i try the  
same in IE or firefox, no matter how i load the page second combo box  
doesn’t gets updated at all.  
By the way i checked in the error console after i load the page in  
firefox by directly passing [http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking)  
there was ‘form is not defined’ heree is the extracted line as i  
couldn’t make any sense of it:  
new Form.Element.EventObserver(‘great\_walks’, function(element, value)  
{new Ajax.Updater(‘campsites\_list’, ‘/user/update\_campsites’,  
{asynchronous:true, evalScripts:true, parameters:‘id=’ + value +  
‘&authenticity\_token=’ +  
encodeURIComponent(‘596f343332f1b5ff9a9bcd36fe9545a71a293677’)})})

thanks.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/8 "2008-10-08T15:58:22Z")

</div>

On 8 Oct 2008, at 14:46, Jay P. wrote:

> > > then  
> > > Your first step has to be to identify which of the above are  
> > > By the way i checked in the error console after i load the page in  
> > > firefox by directly passing [http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking)  
> > > there was ‘form is not defined’ heree is the extracted line as i

Assuming it was “Form is not defined”, then it means that the  
prototype javascript library is not being loaded (see  
javascript\_include\_tag)

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/9 "2008-10-08T16:27:03Z")

</div>

Frederick C. wrote:

> On 8 Oct 2008, at 14:46, Jay P. wrote:
> 
> > > > then  
> > > > Your first step has to be to identify which of the above are  
> > > > By the way i checked in the error console after i load the page in  
> > > > firefox by directly passing [http://localhost:3000/user/online\_booking](http://localhost:3000/user/online_booking)  
> > > > there was ‘form is not defined’ heree is the extracted line as i
> 
> Assuming it was “Form is not defined”, then it means that the  
> prototype javascript library is not being loaded (see  
> javascript\_include\_tag)
> 
> Fred

Do i need to use javascript\_include\_tag? coz when it was first working  
when i didn’t have any other page but just that page with combo boxes i  
didn’t use it and also when i used it, it made the page loading terribly  
slow but didn’t solve the problem. I put \<%=javascript\_include\_tag  
:defaults%\>.

Also the error console in firefox gives lots of error like syntax error,  
missing ‘)’, missing ‘}’, etc etc so 'm more confused.  
thnx..

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/10 "2008-10-08T16:36:04Z")

</div>

On 8 Oct 2008, at 15:27, Jay P. wrote:

> > Assuming it was “Form is not defined”, then it means that the  
> > prototype javascript library is not being loaded (see  
> > javascript\_include\_tag)
> > 
> > Fred
> 
> Do i need to use javascript\_include\_tag? coz when it was first working

If you don’t load prototype.js then anything that tries to use it will  
fail.

> missing ‘)’, missing ‘}’, etc etc so 'm more confused.  
> thnx..

Find out why and fix them

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 4:45pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/11 "2008-10-08T16:45:00Z")

</div>

Frederick C. wrote:

> On 8 Oct 2008, at 15:27, Jay P. wrote:
> 
> > Do i need to use javascript\_include\_tag? coz when it was first working
> 
> If you don’t load prototype.js then anything that tries to use it will  
> fail.
> 
> > missing ‘)’, missing ‘}’, etc etc so 'm more confused.  
> > thnx..
> 
> Find out why and fix them
> 
> Fred

thnx fred, i’ll try doing that but before i go to bed as its already  
1:30am one last and silly question: how can i load prototype.js? thnx..

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/12 "2008-10-08T16:51:24Z")

</div>

On 8 Oct 2008, at 15:45, Jay P. wrote:

> > > missing ‘)’, missing ‘}’, etc etc so 'm more confused.  
> > > thnx..
> > 
> > Find out why and fix them
> > 
> > Fred
> 
> thnx fred, i’ll try doing that but before i go to bed as its already  
> 1:30am one last and silly question: how can i load prototype.js?  
> thnx..

that’s was javascript\_include\_tag can do for you (among other things)

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/13 "2008-10-08T17:09:41Z")

</div>

On 8 Oct 2008, at 15:56, Jay P. wrote:

> > > thnx fred, i’ll try doing that but before i go to bed as its already  
> > > 1:30am one last and silly question: how can i load prototype.js?  
> > > thnx..
> > 
> > that’s was javascript\_include\_tag can do for you (among other things)
> 
> but now i’ve put that in my layout but still its not working.

Again, ‘its not working’ is a useless statement.  
Find out exactly why it is not working and you will be well on your  
way to fixing it.

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 9, 2008, 6:13am UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/14 "2008-10-09T06:13:23Z")

</div>

Frederick C. wrote:

> On 8 Oct 2008, at 15:56, Jay P. wrote:
> 
> Find out exactly why it is not working and you will be well on your  
> way to fixing it.
> 
> Fred

I’m trying to find out why?? but I don’t think I can. Until now what  
I’ve found is that the Firefox showing errors in its error console is  
from the default javascripts files of which prototype.js I tried to  
trace the problem as it was saying ‘)’ is missing on some number line.  
So, i went there but found everything is fine. ‘)’ is there. Also, the  
line giving error from my code is:

new Form.Element.EventObserver(‘great\_walks’, function(element, value)  
{new Ajax.Updater(‘campsites\_list’, ‘/user/update\_campsites’,  
{asynchronous:true, evalScripts:true, parameters:‘id=’ + value +  
‘&authenticity\_token=’ +  
encodeURIComponent(‘596f343332f1b5ff9a9bcd36fe9545a71a293677’)})})

but according to api docs, observe\_field generates similar line only.  
Firefox says ‘form is not defined’ and highlights this line. I don’t  
know what to do.. please suggest… thanks..

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 9, 2008, 9:02am UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/15 "2008-10-09T09:02:09Z")

</div>

On Oct 9, 5:13 am, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## from the default javascripts files of which prototype.js I tried to but according to api docs, observe\_field generates similar line only. Firefox says ‘form is not defined’ and highlights this line. I don’t know what to do.. please suggest… thanks..

So is prototype.js loaded or not (the firebug thingy allows you to see  
which .js files are loaded)?

Fred

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 8, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/16 "2008-10-08T16:56:21Z")

</div>

Frederick C. wrote:

> On 8 Oct 2008, at 15:45, Jay P. wrote:
> 
> > > > missing ‘)’, missing ‘}’, etc etc so 'm more confused.  
> > > > thnx..
> > > 
> > > Find out why and fix them
> > > 
> > > Fred
> > 
> > thnx fred, i’ll try doing that but before i go to bed as its already  
> > 1:30am one last and silly question: how can i load prototype.js?  
> > thnx..
> 
> that’s was javascript\_include\_tag can do for you (among other things)

but now i’ve put that in my layout but still its not working.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 9, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/17 "2008-10-09T13:45:41Z")

</div>

Frederick C. wrote:

> On Oct 9, 5:13ï¿½am, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:  
> So is prototype.js loaded or not (the firebug thingy allows you to see  
> which .js files are loaded)?
> 
> Fred

# Hi Fred, I don’t know how I find that, all that is in the error console is:

# missing ) after condition [http://localhost:3000/javascript/prototype.js?1223506315](http://localhost:3000/javascript/prototype.js?1223506315) (Line: 2555) if ( !Prototype.BrowserFeatures.ElementExtensions && document.createElement

thanks.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 9, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/18 "2008-10-09T15:34:11Z")

</div>

Frederick C. wrote:

> On Oct 9, 12:45ï¿½pm, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:  
> That looks a bit mangled to me - that second like reads  
> document.createElement(‘div’). **proto** ) {  
> on my machine.  
> rake rails:update  
> will restore prototype.js from the version in the framework.
> 
> Fred

Actually, I changed its formation as firefox was complaining that ) is  
missing. So, now I did rake rails:update and stopped and restarted the  
server (to be more sure as sometime I found it more trust worthy in my  
view) and started fresh firefox and still got the same thing missing  
complain. Also, the updating thing now all works fine in aptana browser  
but not in firefox. Javascript is also enabled in firefox and same thing  
in IE as well.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 9, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/strange-observe-field-partial-functioning/150417/19 "2008-10-09T14:33:49Z")

</div>

On Oct 9, 12:45 pm, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> =========================================================================== =====  
> missing ) after conditionhttp://localhost:3000/javascript/prototype.js?1223506315 (Line: 2555)  
> if ( !Prototype.BrowserFeatures.ElementExtensions &&  
> document.createElement  
> =========================================================================== =====

That looks a bit mangled to me - that second like reads  
document.createElement(‘div’). **proto** ) {  
on my machine.  
rake rails:update  
will restore prototype.js from the version in the framework.

Fred
