'Include JavaScript in Ruby (on Rails)

I don't quite understand how Rails includes JavaScript files. Google and the following documentations didn't solve my problem:
http://railsapps.github.io/rails-javascript-include-external.html
http://guides.rubyonrails.org/asset_pipeline.html

I understand that Rails uses manifest-files (e.g. applications.js) to pack every included JavaScript file into one big file (performance reasons, etc.).

In application.html.erb you need to include this manifest, like

<%= javascript_include_tag :application %>

I added a JavaScript file to /app/assets/ (e.g. my_javascript.js).
So, if I look at the Source-Code, I can find

<script src="/assets/application.js" type="text/javascript"></script>

and if I open the file, the content of my_javascript.js is rendered in the application.js file.

My Problem: The function is not working. But if I directly include the my_javascript.js in the application.html.erb, like

<%= javascript_include_tag "my_javascript" %>

it is working! Of course, it renders a second script-tag, like:

<script src="/assets/my_javascript.js" type="text/javascript"></script>

So finally, why does the function work if I include it in specific and not if I use the manifest (how it's supposed to)? Do I need to consider something special about the Assets-Pipeline? My manifest includes

//= require_tree .

but I even tried it with

//= require my_javascript

I'm on Rails 3.2.3 with Ruby 1.9.3.

Thank you in advance!



Solution 1:[1]

Try putting in Application Layout

<%= yield :head %> in the between head tags.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hamza Ouaghad