strange observe_field/partial functioning..

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. 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)

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

Fred

Frederick Cheung wrote:

Frederick Cheung 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

Frederick Cheung wrote:

Frederick Cheung wrote:

Frederick Cheung 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 then it works but if i open the index page first which will be 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

Frederick Cheung wrote:

neither any error is shown it happens like as if nothing is set to

http://localhost:3000/user/online_booking then it works but if i
open the index page first which will be 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 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

Frederick Cheung 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 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..

Frederick Cheung 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 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

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

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..

Find out why and fix them

Fred

Frederick Cheung wrote:

Frederick Cheung 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..

that's was javascript_include_tag can do for you (among other things)

Frederick Cheung wrote:

Frederick Cheung 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.

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

Frederick Cheung 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..

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

Fred

Frederick Cheung wrote:

Frederick Cheung 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 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

Frederick Cheung 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.