# \[N00b\] Javascript stopped wrking when move to application.js

**URL:** <https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801>\
**Category:** Rails\
**Created:** [October 9, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801 "2007-10-09T22:37:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 9, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/1 "2007-10-09T22:37:55Z")

</div>

I originally had my view look something like:

\<% @heading = “Bugs” %\>  
\<%= link\_to ‘Bug table’, :action =\> ‘bug\_table’ %\>

 \<% for bug in @bugs %\> [etc., table]

But then I changed it to:

\<% @heading = “Bugs” %\>  
\<%= javascript\_include\_tag :defaults %\> ← new line  
\<%= link\_to ‘Bug table’, :action =\> ‘bug\_table’ %\>

|
| |

 \<% for bug in @bugs %\> [etc., table]

and moved everything between into  
public/javascripts/application.js.

Back when all the JS was in my view.rhtml, everything worked fine. Now  
that it’s in application.js, none of the functions do anything – I  
suspect that they’re not being loaded, somehow.

When I view source for the rendered page, I see

[Bug table](https://www.ruby-forum.com/bugs/bug_table)

|
| |

 [etc.]

And, when I load up application.js?1191286272 and view its source, sure  
enough, there’s my java-script, just as I’d expect.

So… what am I doing wrong?

Thanks!

P.S. Tried to Google + seach archives for this but, apparently, my  
search-fu is weak – Google got me nothing, while this-forum returned  
100s of hits, none of which seemed to address this issue (I searched on  
+javascript +“not.loaded”) Hints there would be helpful, too 🙂

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 6:48pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/2 "2007-10-23T18:48:55Z")

</div>

Ping? 2 weeks and no one knows…?

Summary:

- When I have the javascript code in my aplication.rhtml, it all works  
fine.
- When I move javascript code to public/javascripts/application.js and  
insert %= javascript\_include\_tag :defaults %\> into my application.rhtml,  
none of the javascript calls work.
- [http://locahost:3000/javascripts/application.js](http://locahost:3000/javascripts/application.js) returns a page that  
contains all of the expected javascript.

Thanks!

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/3 "2007-10-23T19:30:47Z")

</div>

Go get Firebug: [http://www.getfirebug.com](http://www.getfirebug.com)

You’re obviously including the javascript into your page, it’s just not  
getting initialized properly.

Jason

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/4 "2007-10-23T20:08:03Z")

</div>

Jason R. wrote:

> Go get Firebug: [http://www.getfirebug.com](http://www.getfirebug.com)  
> You’re obviously including the javascript into your page, it’s just not  
> getting initialized properly.  
> Jason

Ok, this just gets weirder & weirder…

Firebug shows that the javascript is loaded & all seems well. (Maybe  
I’m not clear what I need to check to see that it’s “initialized”…?)

Just as a sanity check, I put the js back in the main file, and  
verified: sure enough, all works correctly. Pulled it back out, no  
workie.

Ok, so where in firebug do I look to see what is different? For what am  
I looking?

Thanks!

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/5 "2007-10-23T21:16:51Z")

</div>

On 23 Oct 2007, at 19:08, Olie D. wrote:

> Just as a sanity check, I put the js back in the main file, and  
> verified: sure enough, all works correctly. Pulled it back out, no  
> workie.
> 
> Ok, so where in firebug do I look to see what is different? For  
> what am  
> I looking?

Set breakpoints and step through them.

Fred

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 8:41pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/6 "2007-10-23T20:41:08Z")

</div>

If there are no errors in the Console, then we’ll need to see what you  
are  
trying to do. The code you’ve posted doesn’t help with solving the  
problem.

Jason

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 10:51pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/7 "2007-10-23T22:51:52Z")

</div>

Basically, you’re code is not executing. I get the feeling that it’s  
supposed to “just run”. This won’t happen in a file because the DOM is  
not  
yet loaded when the script is pulled in. It works in-line because  
javascript  
is run _after_ the DOM is loaded.

You’ll need to wrap the code up in a function that gets called onload  
(any  
time after DOM is loaded, really).

Jason

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 23, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/n00b-javascript-stopped-wrking-when-move-to-application-js/116801/8 "2007-10-23T22:25:25Z")

</div>

Jason R. wrote:

> If there are no errors in the Console, then we’ll need to see what you  
> are  
> trying to do. The code you’ve posted doesn’t help with solving the  
> problem.
> 
> Jason

I’m using “show fully-HTML-savvy tool-tips (so BR, B, I tags, etc)” code  
that I got from a tutorial on the web.

Again, if I put the javascript in the main source, it all works  
perfectly. If I use the javascript tags & js in its own file, it  
doesn’t work.

I’m not sure what parts you want to see. Should I upload a zip-folder  
with some key bits?

Also, Fred, I’m not sure what you’re telling me about breakpoints. I’m  
new to firebug, could you be explicit?

Thanks!
