Reputation: 1591
I'm using Datetimepicker and Slider. I include them in my Gemfile
gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true
source 'https://rails-assets.org' do
# gem 'rails-assets-select2-bootstrap-css'
gem 'rails-assets-seiyria-bootstrap-slider'
end
In my application.js
//= require moment
//= require bootstrap-datetimepicker
//= require pickers
//= require seiyria-bootstrap-slider
This works great in development, but when I run RAILS_ENV=production rake assets:precompile
on the server (capistrano deploy or by hand) these, and others don't seem to get pulled in. Chrome complains specifically about these two first.
I know I could put the line Rails.application.config.assets.precompile += %w( *.js )
and then do a =javascript_include_tag :XXXX
, but this defeats the purpose of sprockets/manifest right?
My understanding with sprockets/manifest is when I require it in my application.js
it'll be included with the deploy so the client hits the server less.
Is there something I'm missing?
EDIT
Traced the problem to the uglifier
gem. When I remove/comment out config.assets.js_compressor = :uglifier
and recompile the JS starts working again.
Any thoughts?
Upvotes: 2
Views: 11063
Reputation: 5112
this is because things work differently in development as compared to production. few thing to note:-
config.precompile
directive.Only application.css
and application.js
are available by default of all the CSS and JS files.public/assets
folder when you compile your assets.So if you want to add some web fonts, you could make an app/assets/fonts/ folder and put your fonts in there, these will then be copied to public/assets/fonts
folder when you compile your assets. Note that your app/assets/stylesheets/fonts.css.scss
file that references those fonts will NOT be copied over unless you either added it to the config.assets.precompile
directive or required it from your application.css
config.assets.compile
...If it is set to "true" (which it is by default in development) then Rails will try to find a Javascript or CSS file by first looking in the public/assets
directory and if it can't find it, will hunt through your app/assets
folder looking for the file. If it finds it in app/assets
it will go ahead and compile on the fly and then serve this asset up.The problem with this is that you don't notice it happening in development, then you commit everything and push to production and BOOM, everything is broken with 500 errors because production has config.assets.compile
set to "false".This prevents the app from "falling back" and trying to load the file directly instead of using the asset pipeline.
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
Why don't you just have this set to "true" in every environment? Well, because it is sloooooow. And you don't want slow in production
RAILS_ENV=production rake assets:clean assets:precompile
Upvotes: 7