Reputation: 251
Would like to put any js functions in application.js or other .js file.
However, doing ajax experiments I'm finding only the javascript functions are only working if placed in application.html.erb.
If I put them in application.js I end up with non-helpful browser errors.
Have experimented with both link_to and XMLHttpRequest directly
Any thoughts? Shouldn't application.js be generally visible?
Upvotes: 1
Views: 377
Reputation: 4144
No. application.js is only visible if you explicitly include in your HEAD section as:
<%= javascript_include_tag 'application.js' %>
If you do:
<%= javascript_include_tag :defaults %>
it also looks for application.js.
The code below is what I'm using to include jQuery, jQuery-UI and my own application.js
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" %>
<%= javascript_include_tag "application.js" %>
Upvotes: 2