I have a problem with running js/jquery in my rails app.
I have Ruby 1.9.3 and Rails 3.2.3 installed.
I have two js files in /app/assets/javascripts:
application.js
main.js
I created this main.js. In it there is this code
$(document).ready(function() {
alert('Hello world!');
});
my application.js has the following:
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require main.js
When I open my app, no alert message pops up!
Opening the source code, i see all the js files in place:
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/main.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
What I am doing wrong???
Ok guys, I made a mistake.
I gave false information about the name of my js file for abstracting purposes.
The originial name of my was advert.js and for whatever reason it does not get executed as js.
I remembered that I used advert.css in this project and it was also not recognized by rails as css, even if it was loaded. I renamed that advert.css to popup.css and it worked, so it did now with my advert.js. Renamed it to popup.js and it works!