My experience with rails and Javascript is very limited.
I am trying to pop up a basic alert function to make sure everything is in working order however its not working therefor things are not in working order!
When the index page is loaded run this code every single time:
$(document).ready(function() {
alert('Welcome to index!');
});
That code is currently located in a file in assets/javascript/default.js
In my application.html.erb, in the header I have added
<%= javascript_include_tag :default %>
and in my controller under index format I have also added
format.js { render 'default.js'}
when I run the page with firebug under scripts it does see
<script type="text/javascript" src="/assets/default.js?body=1">
although I dont understand the body=1 part yet, and under scripts it does show the code, so clearly the browser can see the code however for some reason is not executing it.
In my gems i have jquery-rails(1.0.19) and bundle install has already been run.
I have tried that page with firefox, internet explorer, and chrome to no avail. and I apologize if I have already missed such a question.
I thank you all for your time.
In Rails 3.1, you should be using
'application', not'default':This will load the
app/assets/javascript/application.jsfile which is really just a manifest to load all your other javascript files, including jQuery:It loads jQuery, then the
require_tree .line loads all other javascript files.With your code as it is, jQuery is never loaded, so it doesn’t understand the
$function.