Forum: Ruby on Rails weird prototype error when using RJS

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.
2c0a2cbea5455db466aed567de71bfd2?d=identicon&s=25 Andrew Gibson (esquilax)
on 2006-05-17 21:05
I'm trying to set up a nested menu strucutre using RJS

I want to be click on an item, have not have the whole page refresh but
just have the menu <li id='Selection'> refreshed

1 - my model is using :acts_as_tree

2 - in my controller I have the following.. it's just a barebones start
at being able to dig DOWN through the chilren
  def renderMenu
    render :update do |page|
      page.replace_html "Selection", :partial => 'selection',
:collection => Program.find(params[:id]).children
   end
  end

3- my :partial => 'selection' is the following "_selection.rhtml" file
<li><%= link_to_remote selection.name, :update => "Selection", :url =>
{:action => :renderMenu, :id => selection.id} %> </li>

4- my layout provides the following strucutre:
   <div>
	<ul id="Selection">
	<%= render :partial => 'selection', :collection =>
@menu[:BreadCrumb][-1].children %>
	</ul>
   </div>


-------anyways :) so this is hte problem i'm having:
it sort of works but I think i'm getting a prototype error...when I
click on a parent element to see its children, I get a mix of what I
want and an error message..all mixed up

try { Element.update("Selection", "
<half the children displayed properly>
"); } catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"Selection\", \"
<second half of the children>
\");'); throw e }

any suggestions?
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-05-17 21:18
Andrew Gibson wrote:
> try { Element.update("Selection", "
> <half the children displayed properly>
> "); } catch (e) { alert('RJS error:\n\n' + e.toString());
> alert('Element.update(\"Selection\", \"
> <second half of the children>
> \");'); throw e }

That try/catch stuff is just there for RJS debugging.  So that when some
javascript error occurrs you will get an alert with the details of the
error.

But is the javascript actually executing? or is it just showing up on
the page as text?  If it's showing up as text you need to set:

@headers['Content-Type'] = 'text/javascript'

Although if you use "render :update" that should be done for you.  Get
the Firebug extension for Firefox so you can examine the headers and
content of the response to your ajax calls.  It should help you figure
out whats going on.
2c0a2cbea5455db466aed567de71bfd2?d=identicon&s=25 Andrew Gibson (esquilax)
on 2006-05-17 21:24
the javascript is executing..the child elements are apeparing..but
they're being around by the javascript error handling output

Alex Wayne wrote:
> Andrew Gibson wrote:
>> try { Element.update("Selection", "
>> <half the children displayed properly>
>> "); } catch (e) { alert('RJS error:\n\n' + e.toString());
>> alert('Element.update(\"Selection\", \"
>> <second half of the children>
>> \");'); throw e }
>
> That try/catch stuff is just there for RJS debugging.  So that when some
> javascript error occurrs you will get an alert with the details of the
> error.
>
> But is the javascript actually executing? or is it just showing up on
> the page as text?  If it's showing up as text you need to set:
>
> @headers['Content-Type'] = 'text/javascript'
>
> Although if you use "render :update" that should be done for you.  Get
> the Firebug extension for Firefox so you can examine the headers and
> content of the response to your ajax calls.  It should help you figure
> out whats going on.
455ac2a64d06dc8461f4d258d7f7e980?d=identicon&s=25 Michael Trier (Guest)
on 2006-05-17 22:28
(Received via mailing list)
a couple of things.  First you're not just updating the <li>, you're
updating the whole ordered lists.  In your partial you don't need the
:update symbol in there.  Finally, like the other poster said, get
Firebug.  Turn on the Options >> ShowXHTMLRequests.  View your Console
and look at the Request as well as the Response.  I suspect you'll
find the problem.

Michael
2c0a2cbea5455db466aed567de71bfd2?d=identicon&s=25 Andrew Gibson (esquilax)
on 2006-05-17 22:38
AAAAh.... thanks :)  the :update did the trick

Michael Trier wrote:
> a couple of things.  First you're not just updating the <li>, you're
> updating the whole ordered lists.  In your partial you don't need the
> :update symbol in there.  Finally, like the other poster said, get
> Firebug.  Turn on the Options >> ShowXHTMLRequests.  View your Console
> and look at the Request as well as the Response.  I suspect you'll
> find the problem.
>
> Michael
This topic is locked and can not be replied to.