Strange observe_field/partial functioning


#1

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)

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.


#2

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…


#3

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


#4

On Oct 8, 12:58 pm, Jay P. 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


#5

Frederick C. wrote:

On Oct 8, 12:58�pm, Jay P. 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 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


#6

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


#7

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


#8

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


#9

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


#10

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


#11

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…


#12

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)


#13

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


#14

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…


#15

On Oct 9, 5:13 am, Jay P. 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


#16

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.


#17

Frederick C. wrote:

On Oct 9, 5:13�am, Jay P. 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 (Line: 2555)
if ( !Prototype.BrowserFeatures.ElementExtensions &&
document.createElement

thanks.


#18

Frederick C. wrote:

On Oct 9, 12:45�pm, Jay P. 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.


#19

On Oct 9, 12:45 pm, Jay P. 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