Index to show lost javascript

I am testing a local copy of my website using mongrel trying to
introduce a scriptaculous multi-level drop down menu. the menu is a
partial that is loaded into every layout I have many pages with their
individual layout. When I jump from page to page all works OK. When I
jump from any “view/index” to “view/show” I lose the javascript and the
drop down menu only works on the first level. Can anyone shed some light
on why this happens and how I can solve it. In my layouts heads I have
the following:-

Blogpictures: <%= controller.action_name %> <%= stylesheet_link_tag 'style' %> I am using the control.js protype.js etc that came with the scriptaculous download also using the latest versions of Ruby, Rails, Gems etc.

Hi Don:

I’m not sure what whether this will fix your problem But as I can see
your javascript includes are wrong

it should be like

Note that you are missing the starting ‘/’

or else you can use

<%= javascript_include_tag :defaults %>

hope this helps

cheers,
sameera

Thanks Sameera
The problem was that I was mixing HTML and Ruby.

etc Instead of <%= javascript_include_tag "prototype.js"%> etc I will use the single line <%= javascript_include_tag "prototype.js", "scriptaculous", "menu"%> as I do not require all the Javascript to be loaded ie. not <%= javascript_include_tag :defaults%> as I have read this adds a lot to the loading overhead. (Any saving in loading time will be appreciated.) What was happening was that the HTML would only work from the root and show, edit etc are relative links and could not find the source. Therefore using pure Ruby solves the problem as Ruby puts in the links for all templates(show, edit etc.) Many thanks again Don

Don Mapp wrote:
[…]

What was happening was that the HTML would only work from the root and
show, edit etc are relative links and could not find the source.
Therefore using pure Ruby solves the problem as Ruby puts in the links
for all templates(show, edit etc.)

No, what was happening was that your URLs were wrong. The Rails helpers
generate them correctly, but you don’t have to use the helpers to get
correct URLs.

Many thanks again Don

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Thanks for that insight Marnen.
I will look into it later. I am not sure what you mean by my urls were
wrong? What I think happened was that my “src =” neded the full path to
work properly. Using <%= javascript_include_tag
“prototype.js”,“scriptaculous.js”,“menu.js” %> has solved the problem
for the mo, but I will have to try and work out exactly why my previous
mix of HTML and Ruby did not work in all templates. In programming you
never know when you may have to use the mix of HTML and Ruby. If you can
give me some more simple explanation I would be grateful.
Don

Marnen Laibow-Koser wrote:

Don Mapp wrote:
[…]

What was happening was that the HTML would only work from the root and
show, edit etc are relative links and could not find the source.
Therefore using pure Ruby solves the problem as Ruby puts in the links
for all templates(show, edit etc.)

No, what was happening was that your URLs were wrong. The Rails helpers
generate them correctly, but you don’t have to use the helpers to get
correct URLs.

Many thanks again Don

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Thanks for trying Marnen.
Pardon my inability to get what exactly you are saying.
I think get the drift of what you are saying, but I think of “src =” as
having a path not a URL and the path is local to the root w/site on the
server.

I feel that if I gave it a full path to “src =” it would work OK. I will
try that later as at the moment I am making minor adjustment to the site
after uploading my modifications.
I have just finished most of the additions and have to go to that thing
called work.
I will do a full check on the site tomorrow and see if I need any more
modifications. So far it seems to works in Safari, Firefox, and
Explorer.
You can check the sites out at donsgarden.co.uk and donspace.co.uk
Don

Don Mapp wrote:

Thanks for trying Marnen.
Pardon my inability to get what exactly you are saying.
I think get the drift of what you are saying, but I think of “src =” as
having a path not a URL and the path is local to the root w/site on the
server.

Then you are thinking wrong. In HTML, virtually any tag’s src or href
attribute takes a URL. That URL can be relative (in which case it’s
equivalent to a path) or absolute (
http://some.server.across.the.world/script.js ).

I feel that if I gave it a full path to “src =” it would work OK.

You’re right. If you look at the HTML that the Rails helpers generate,
you will see that this is exactly what they do.

Remember: when in doubt, inspect what is generated.

I will
try that later as at the moment I am making minor adjustment to the site
after uploading my modifications.

Just try stuff in a separate version control branch, and make sure you
write tests so you know what you’re finding.

I have just finished most of the additions and have to go to that thing
called work.
I will do a full check on the site tomorrow and see if I need any more
modifications. So far it seems to works in Safari, Firefox, and
Explorer.

Well, yeah, a correct URL should be correct in any browser.

You can check the sites out at donsgarden.co.uk and donspace.co.uk
Don

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Don Mapp wrote:

Thanks for that insight Marnen.
I will look into it later. I am not sure what you mean by my urls were
wrong? What I think happened was that my “src =” neded the full path to
work properly.

Right. The URL in the src attribute was incorrect – which is what I
meant.

Using <%= javascript_include_tag
“prototype.js”,“scriptaculous.js”,“menu.js” %> has solved the problem
for the mo, but I will have to try and work out exactly why my previous
mix of HTML and Ruby did not work in all templates.

It’s not a question of HTML versus Ruby – please stop thinking of it in
those terms. It’s simply a question of incorrect versus correct paths.

In programming you
never know when you may have to use the mix of HTML and Ruby. If you can
give me some more simple explanation I would be grateful.

Very simple: the client has no way of knowing which you used, so the
only way to choose is to determine which makes it easier to get the
output you want.

In this case, it’s certainly easier to have Rails’ helpers build the
paths. But there’s nothing magical about that – nothing that you
couldn’t do with literal HTML – and that’s the distinction I was
making.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Don

Marnen Laibow-Koser wrote:

Don Mapp wrote:
[…]

What was happening was that the HTML would only work from the root and
show, edit etc are relative links and could not find the source.
Therefore using pure Ruby solves the problem as Ruby puts in the links
for all templates(show, edit etc.)

No, what was happening was that your URLs were wrong. The Rails helpers
generate them correctly, but you don’t have to use the helpers to get
correct URLs.

Many thanks again Don

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]