Related to the same question (Loading Javascript per controller in rails)
I want to load a separated javascript file when this controller and one of its views is processed.
So I have some javascript code that works very well, but I want to outsource this code for the controller orders_now. So I paste this code into this file app/assets/javascripts/orders_now.js :
function request_loading_stations ()
{
$.ajax({
method: "post",
url: "/orders_now/search_for_loading_stations",
data: { order_now_post: { loading_station_text_field: $('#loading_station_text_field').val() } }
})
};
I did also an entry in config/initializers/assets.rb :
Rails.application.config.assets.precompile += %w( orders_now.js )
In the corresponding view I did the following entry to load the orders_now.js file.
<%= javascript_include_tag params[:controller] %>
Then I also restarted the Rails Web Server.
When I reload the Browser Page, the javascript file seems to be not loaded.
In the Browser Developer Tools I can see the javascript file is included:
<script src="/assets/orders_now.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1"></script>
But when I want to check the content of this file I see only:
(function() {
}).call(this);
What's going wrong ?