I am using Rails 3.1 and under assets I have files like this:
assets
javascripts
admin
admin.js
a1.js
client
client.js
c1.js
admin.js looks like this
//
//= require jquery
//= require jquery_ujs
//= require a1
client.js looks like this
//
//= require jquery
//= require c1
Everything works fine in development mode. When I do rake assets:precompile then I do not see any javascript files in public/assets. I do see all the stylesheets in public/assets.
I think this has to do with the fact that manifest files (admin.js and client.js) in this case are in subdirectory.
So is this true that rake assets:precompile does not look into subdirectories?
Any suggestions on how to fix this. I prefer to have the files the way I laid out because I have a bunch of javascript files.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
RAILS_ENV=production tells Rails to compile the production version of the assets. assets:precompile is a Rails provided rake task that has instructions for compiling the assets.
Sprockets is a crucial Ruby library that is used to serve and compile web assets. However, in Rails 7.0 the library becomes an optional dependency unless the application needs to use Sprockets. In such situations, the sprockets-rails gem will have to be added to the Gemfile .
There is a precompile array in the Rails config that sets what files to precompile. application.js and application.css in any directory.
You will need to add your files to the precompile array:
config.assets.precompile += ['admin/admin.js', 'client/client.js']
And they should be accessible via:
javascript_include_tag "admin/admin.js"
and
javascript_include_tag "client/client.js"
At rails 3.2.6, when managing javascript assets in subdirs, you can name the manifest for each subdir 'index.js' (as opposed to OP's 'admin.js' and 'client.js'), and then in config/environments/production.rb say:
config.assets.precompile += ['admin.js', 'client.js']
Magic behind the scenes will look in the admin subdir and compile according to the specs in index.js, outputting to admin.js; likewise for client.
The assets will then be accessible via:
javascript_include_tag 'admin'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With