Weird prototype error when using RJS

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

  • 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

  • <%= link_to_remote selection.name, :update => "Selection", :url => {:action => :renderMenu, :id => selection.id} %>
  • 4- my layout provides the following strucutre:

      <%= render :partial => 'selection', :collection => @menu[:BreadCrumb][-1].children %>

    -------anyways :slight_smile: 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”, "

    "); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());
    alert(‘Element.update(“Selection”, "

    ");’); throw e }

    any suggestions?

    Andrew G. wrote:

    try { Element.update(“Selection”, "

    "); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());
    alert(‘Element.update(“Selection”, "

    ");’); 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.

    the javascript is executing…the child elements are apeparing…but
    they’re being around by the javascript error handling output

    Alex W. wrote:

    Andrew G. wrote:

    try { Element.update(“Selection”, "

    "); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());
    alert(‘Element.update(“Selection”, "

    ");’); 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.

    AAAAh… thanks :slight_smile: the :update did the trick

    Michael T. wrote:

    a couple of things. First you’re not just updating the

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

  • a couple of things. First you’re not just updating the

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