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

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

[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 :slight_smile:

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 returns a page that
    contains all of the expected javascript.

Thanks!

Go get Firebug: http://www.getfirebug.com

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

Jason

Jason R. wrote:

Go get Firebug: 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!

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

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

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

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!