Insert.html working weirdly

Not sure what’s going on here but the js is printing out on the page along with what should be rendered.

I have an index page, so in the helper, I created this function:

module IndexHelper
def menu
render :update do |page|

page.insert_html :bottom, 'subnav' , :partial => 'navigation'


Then in the layout page:

<%= menu %>

Finally in the navigation partial:

<% if current_user.level = 1 %>

Navigation for Company

<% elsif current_user.level = 2 %>

Navigation for User

<% end %>

Yet , what is getting printed on the page is :

try {
new Insertion.Bottom(“subnav”, “\n
Navigation for Company
} catch (e) { alert(‘RJS error:\n\n’ + e.toString());
alert(‘new Insertion.Bottom(“subnav”, “\n
Navigation for Company\n\n\n”);’); throw e }

So, one thing is it’s spitting back the right text but twice,
then I don’t understand why the js is printing out.


I guess. I don’t understand why there would be a rendering of the js to the page.
So, then yes I would jsut want to render the partial.


I want the insert_html to update the div .


Should I not have the insert_html in the helper.rb file ?


I need the javascript becasue the page / layout doesn’t fully reload. What I can’t figure out is how to
use a rjs template in this situation. Having it in the helper file seems to be the
only way it works , yet for some reason, it’s rendering the lines of javascript to the screen along with
what is intended to be shown.


render :update and RJS templates do exactly this. They render
JavaScript the brwoser has to evaluate ...
but they dont apply any <script> tags because what they are
intentionally meant for are AJAX calls. and that AJAX Object evaluates
the JavaScript:

If you use a RJS template in a helper, it wont be evaluated as there's
no AJAx Object to receive the JavaScript generated by the template.

I still cant get a clear pitcure of what you actually trying to do (you
say it doesn't completely refresh ... spounds like AJAX ... where's the
AJAX call then?), sure render :partial won't work? did you try it?

From your code, you only render a partial through some javascript, and

then insert that javascript in a div tag thorugh a helper...

layout calls helper "menu" -> menu calls render :update > render
:update call render :partial> partial gets rendered ... but IN

why should this not work:
layout calls helper "menu" -> menu calls render :partial -> partial
gets render ... in HTML (which is what you want obviously ...)

Okay, I got this working without any javascript / Ajax calls. Just rendering the navigation partial is fine.


Hey Alan, that pretty much sums up very nicely what i tried to say with
my whacky english :smiley:

Nice Explanation indeed ...

Thorsten, my apologies for not replying sooner. Yes, your explanation helped.