# Index to show lost javascript

**URL:** <https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574>\
**Category:** Rails\
**Created:** [November 29, 2009, 5:42am UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574 "2009-11-29T05:42:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [November 29, 2009, 5:42am UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/1 "2009-11-29T05:42:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [November 29, 2009, 6:30pm UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/2 "2009-11-29T18:30:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [November 29, 2009, 10:23pm UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/3 "2009-11-29T22:23:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [November 29, 2009, 11:46pm UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/4 "2009-11-29T23:46:30Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [November 30, 2009, 6:30pm UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/5 "2009-11-30T18:30:00Z")

</div>

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](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [December 1, 2009, 12:27am UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/6 "2009-12-01T00:27:51Z")

</div>

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](http://donsgarden.co.uk) and [donspace.co.uk](http://donspace.co.uk)  
Don

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [December 1, 2009, 12:43am UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/7 "2009-12-01T00:43:53Z")

</div>

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](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](http://donsgarden.co.uk) and [donspace.co.uk](http://donspace.co.uk)  
> Don

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [November 30, 2009, 7:24pm UTC](https://www.ruby-forum.com/t/index-to-show-lost-javascript/179574/8 "2009-11-30T19:24:15Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

> 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](http://www.marnen.org)  
> > removed\_email\_address@domain.invalid
