Reputation: 4492
I am using the requirejs-rails gem along with a variety of 3rd party javascripts. In dev, this all seems to be working... even when precompiling my assets, however in staging/production (heroku) it cant find the assets.
Take jQuery for example (using the jquery-rails gem). From the heroku console if I do
Rails.application.assets.find_asset('jquery.min')
it finds the asset
(/app/vendor/bundle/ruby/1.9.1/gems/jquery-rails-2.1.1/vendor/assets/javascripts/jquery.min.js").
However if i try to browse to it domain.com/assets/jquery.min.js
i get a 404.
My requirejs-rails config is:
shim:
jquery:
exports: '$'
jquery-ujs:
- jquery
paths:
jquery: jquery.min
jquery-ujs: jquery_ujs
in my application.js.coffee i have
require ['jquery', 'jquery-ujs'], ($) ->
// ...
Upvotes: 4
Views: 2928
Reputation: 177
The way requirejs-rails
works (and indeed r.js from requirejs) is that it will compile all your javascript files that it know about (via paths in requirejs.yml
or via actual define calls in your code) into one big file that can be then uglified, compressed and cache-busted (by including a digest in the name). Hence if you have a file called /assets/views/my_view.js
that was accessible in dev over http is no longer there in production (because it is part of your application.js
).
In your case if you look at application-<digest>.js
in production (you can get the actual digest by looking at the html of your served application page) you will see that jquery is already included in there (you can see the license comments).
So the file is there, it is served correctly as part of application-<digest>.js
and you should not in production relying on it being available directly. Since the whole point of asset pipeline and requirejs-rails plugin is to compile all the files into one minified, compressed file to improve page performance.
Upvotes: 3
Reputation: 5586
I haven't used requirejs, but have you checked Rails.application.assets.paths
to make sure which has the asset is there? Also make sure config.action_controller.asset_host
is set properly in the current environment
Upvotes: 0