Forum: Ruby on Rails strange observe_field/partial functioning..

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.
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 11:21
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)
================================================================================
<p>
    <label for = "walk location">Locations</label><br />
    <%= select(:selected, :location, Greatwalk.find_available_locations,
        {:prompt=>'Select Great Walk Location'}, :id => :great_walks) %>
</p>
    <%= observe_field("great_walks", :url => {:controller => "user",
:action => "update_campsites"},
              :update => "campsites_list", :with => "id")%>
<div id ="campsites_list" >
  <p>
       <label for = "state">Campgrounds</label> <br />
         <%= select("selected","campsites", %w{ -- }, :class =>
"select_campsites") %>
    </p>
</div>
    <%=button_to "Add to Cart", :action => :add_to_cart, :id =>
"campsites"%>
================================================================================

IN PARTIAL (_campsites.rhtml)
================================================================================
<p>
  <label for="camp location">Campgrounds</label><br/>
  <%=select "selected", "campsite", @resultset %>
</p>
================================================================================

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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 12:22
(Received via mailing list)
On 8 Oct 2008, at 10:21, Jay Pangmi 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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 13:58
Frederick Cheung wrote:
> On 8 Oct 2008, at 10:21, Jay Pangmi 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..
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 14:12
(Received via mailing list)
On Oct 8, 12:58 pm, Jay Pangmi <rails-mailing-l...@andreas-s.net>
wrote:
> Frederick Cheung wrote:
> > On 8 Oct 2008, at 10:21, Jay Pangmi 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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 14:32
Frederick Cheung wrote:
> On Oct 8, 12:58�pm, Jay Pangmi <rails-mailing-l...@andreas-s.net>
> wrote:
>> Frederick Cheung wrote:
>> > On 8 Oct 2008, at 10:21, Jay Pangmi 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 14:46
(Received via mailing list)
On 8 Oct 2008, at 13:32, Jay Pangmi 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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 15:46
Frederick Cheung wrote:
> On 8 Oct 2008, at 13:32, Jay Pangmi 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 15:58
(Received via mailing list)
On 8 Oct 2008, at 14:46, Jay Pangmi 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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 16:27
Frederick Cheung wrote:
> On 8 Oct 2008, at 14:46, Jay Pangmi 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..
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 16:36
(Received via mailing list)
On 8 Oct 2008, at 15:27, Jay Pangmi 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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 16:45
Frederick Cheung wrote:
> On 8 Oct 2008, at 15:27, Jay Pangmi 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..
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 16:51
(Received via mailing list)
On 8 Oct 2008, at 15:45, Jay Pangmi 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)
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-08 16:56
Frederick Cheung wrote:
> On 8 Oct 2008, at 15:45, Jay Pangmi 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-08 17:09
(Received via mailing list)
On 8 Oct 2008, at 15:56, Jay Pangmi 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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-09 06:13
Frederick Cheung wrote:
> On 8 Oct 2008, at 15:56, Jay Pangmi 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..
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-09 09:02
(Received via mailing list)
On Oct 9, 5:13 am, Jay Pangmi <rails-mailing-l...@andreas-s.net>
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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-09 13:45
Frederick Cheung wrote:
> On Oct 9, 5:13�am, Jay Pangmi <rails-mailing-l...@andreas-s.net>
> 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-09 14:33
(Received via mailing list)
On Oct 9, 12:45 pm, Jay Pangmi <rails-mailing-l...@andreas-s.net>
wrote:
> =========================================================================== =====
> missing ) after conditionhttp://localhost:3000/javascript/prototype.js?1223... 
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
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-09 15:34
Frederick Cheung wrote:
> On Oct 9, 12:45�pm, Jay Pangmi <rails-mailing-l...@andreas-s.net>
> 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.
This topic is locked and can not be replied to.