views:

92

answers:

1

My knowledge of Ruby on Rails and javascript is rudimentary so please forgive me if this question has a simple answer. I have a website that needs a multi level dropdown menu. I have adapted scriptalculous drop down menu which is working on a test copy of my website using mongrel. There are several pages each with its own layout. When I jump from page to page the drop down menu works fine, but when I go to any "view/show" page only the first level menu works. I suspect that jumping to show loses the javascript somehow. Anybody knows how to solve this problem. In all my layout head I have the following:-

<%= stylesheet_link_tag 'style' %>
<%= javascript_include_tag :defaults %>
<script src="javascripts/prototype.js" type="text/javascript"></script>
<script src="javascripts/scriptaculous.js" type="text/javascript"></script>
<script type='text/javascript' src='javascripts/menu.js'></script>

I am using the protype, controls etc that came with Scriptaculous download.

A: 

sounds most likely that your problem lies outside of the short code snippet included in your question.

Have you checked with Firebug to see if the menu is being built and sent appropriately, that all of the needed files are included, etc.? (might not even be a javascript issue)

There are lots of other possibilities but it's rather hard to determine from the code provided.

Given that the other pages in your site have working menus, and presumably the menu is the same across pages (navigation menu, I'd guess), then it is extremely likely that the markup or javascript files are different (unclosed tags, missing tags, inline css with display:none, etc)

Jonathan Fingland
Thanks Jonathanproblem solvedShould use javascript_include_tag not "src =..." as url wrong when the pages go from the root templates (index) to the relative link (index to show). Rails cannot resolve the URL from "src =...." Using javascript_include_tag Rails puts the link in all templates (index, show, etc.). If I put full path in "src =...." it should work, as all templates get correct URLs by Rails. Still need to try this. Simpler to let Rails do links using "..._tag "script???", "proto..", "menu";" Did not use "...de_tag:default" that loads all .js some not need, which slow page loading.
Don
should not significantly slow loading as long as the files are cached. Unless the script execution time is particularly slow.
Jonathan Fingland