I am currently working on a Rails application that uses the bootstrap-sass gem to help style some of my front end views. When running locally, I have no problem browsing the views. After Heroku deployment, I receive the following error:
ActionController::RoutingError (No route matches [GET] "/assets/bootstrap-responsive.css")
Here is a snippet of my application.rb file:
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.compile = true
config.assets.initialize_on_precompile = false
Any thoughts as to how to get bootstrap-sass working on a Heroku deployment with asset pre-compilation?
Did you install the 12factor gem? You'll need that with Rails
gem 'rails_12factor', group: :production
https://devcenter.heroku.com/articles/getting-started-with-rails4#heroku-gems
I had my bootstrap import statements in my application.css file. By moving to a bootstrap_and_overrides.css.scss file, my problem was solved.
This post helped: Getting bootstrap-sass bootstrap CSS into production on Heroku
Related
I'm running a Rails 5 app, Ruby 2.4 specified in my Gemfile. I've read through the Heroku assets pipeline article, and gone through the steps as I think I should.
In config/environments/production.rb:
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
In /config/assets, I have these lines:
Rails.application.config.serve_static_assets = true
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( customers.js )
customers.js is the only file I specifically include at the top of a page, and Rails requires me to precompile it..
Just before deploying to Heroku using git, I run this command:
RAILS_ENV=production bundle exec rake assets:precompile
If you go to https://crateu.herokuapp.com, you'll see the stylesheet isn't handling the nav properly (I'm using the Materialize gem). What's confusing to me, is that the javascript is working for the dropdown items. And the styles that handle the nav are in application.sass, and the file is included - it's just not working.
If you go to an invalid URL, such as https://crateu.herokuapp.com/badurl, everything looks the way it should.
I have //= require_tree . in application.js, and when I view the source locally, I see all the files in the pipeline, and everything renders properly. I copied and pasted that source into 404.html in /public, which is why that page renders properly. When I view source on the herokuapp, none of those resources are included in the header. I'm sure it's something simple, a setting somewhere that I'm missing. Maybe I need to include everything in this line, not just customers.js?
Rails.application.config.assets.precompile += %w( customers.js )
I've tried everything I can think of. Any help would be greatly appreciated.
I'll put the response here because the comment section doesn't allow to me to put multiline code, you've to add to you Gemfile:
group :assets do
gem 'uglifier'
end
I have searched around and can't rectify the situation based on the responses to other similar questions. I seem to have broken the asset pipeline somehow but can't seem to figure out how.
None of my assets are being loaded at all; rails seems to just be ignoring my manifest files. When I inspect my page in firebug, only the 'non-compiled' text inside my manifest files (both js and css) is being displayed - almost as if the asset pipeline wasn't even enabled.
I deleted the contents of public/assets since I was adding a new file to the manifest which seemed to start this behavior.
Current configuration:
environments/development.rb
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
application.rb
# Enable the asset pipeline
config.assets.enabled = true
config.assets.manifest = config.root
# Add extra assets for precompiling
config.assets.precompile += ['admin.js', 'admin.css']
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
I had the same issue. You can still use Ruby 2.1.2, just upgrade rails to latest 3.2.x version - it's 3.2.22
Gemfile:
gem 'rails', '3.2.22'
And run:
$ bundle update rails
The issue was caused by using an incompatible version of ruby. I was using version 2.1.2 which lead to unusual behavior from the sprockets gem (which powers the asset pipeline). This was fixed by downgrading to ruby 1.9.3. I haven't done any experimentation for fear of breaking it again but maybe this has been addressed in later versions of sprockets. I am using sprockets 2.1.3.
See: Rails 3.2.8 Application.js and Application.css are not working as expcted
Always remember two things when you want to handle Rails asset pipleline:-
if you want all you newly created js/css to autoinclude in application.js/css,pls add them in...
ELSE
IF you dont wont to add in manifest file(application.js/css) then use precompile directive in yuur environment file.
config.assets.precompile=%w(custom.css,custom2.js...etc)
so make sure you have either of these...
===========for example=-=============
suppose you have new css/js file:-
custom.css inside
app/assets/stylesheets/
so you can include in
application.css
// = require 'custom'
OR
use precompile directive:-
config.assets.precompile += %w( custom.css )
and then reference it like you always do
stylesheet_link_tag "custom"
same applies for js also
I just spent a few hours troubleshooting this issue (in 2017!) and it turned out I just needed to remove the gem active_reload. Updating rails and ruby was having no effect for me. The thread where I found that gold is here:
https://github.com/rails/rails/issues/2715
I just updated a Rails 3.2.x app to 4.0.2.
When I deployed to production (ubuntu, MRI 2.0) I got the good old error about the lack of a javascript runtime.
I quickly fixed it by installing node, but it makes me wonder.
I prefer to precompile the assets locally, check them into git, and then push them to the production server along with the rest of the application.
With Rails 3.2 this system has always allowed me to not care about a js runtime in production, as the application doesn't need to compile coffeescript or run uglyfier.
So, the question is: what has changed with Rails 4? Is there a config option to control this behaviour?
I checked my (rails 4) config file, and I think that the production evironment is already configured to NOT fallback to live compilation.
assets-related config options:
config/application.rb
config.assets.precompile += ['html5shim.js']
config.assets.initialize_on_precompile = false
config/environments/production.rb
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
In case someone hit this question as I did. I had the same problem and this link pointed me to the right direction: https://mattbrictson.com/upgrading-to-rails-4-with-capistrano. Specifically the following statement: In Rails 4, the standard Gemfile no longer has an :assets group, which means asset pipeline gems are always loaded in production, on all servers. I precompile my assets locally and upload them to production, so there is no reason to have JS runtime on production server.
In my case I added group :asset to my Gemfile putting there asset-related gems. In my case it was:
group :asset do
gem 'uglifier'
gem 'execjs'
end
My capistrano tasks on production install bundle without :asset group, so after this change JS runtime is no longer required on production.
My gemfile recently upgraded my compass-rails gem. I started getting the following error (production on heroku only - works fine locally), and have been stuck on it for hours:
Completed 500 Internal Server Error in 14284ms
2012-09-03T20:53:25+00:00 app[web.1]:
2012-09-03T20:53:25+00:00 app[web.1]: ActionView::Template::Error (File to import not found or unreadable: compass/css3.
2012-09-03T20:53:25+00:00 app[web.1]: Load path: Sass::Rails::Importer(/app/app/assets/stylesheets/application.css.scss)
I think part of the problem must lie within the fact the /app/app/ is appearing in the path here - but I dont understand why. When I change the compass config below, to "assets/stylesheets" I still see /app/app/ in the trace error.
production.rb:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
compass.rb
# Require any additional compass plugins here.
project_type = :rails
sass_dir = "app/assets/stylesheets"
Gemfile
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier', '1.2.4'
gem 'yui-compressor', '0.9.6'
gem 'compass-rails'
end
In my application.css.scss file:
#import "compass/css3";
I've been trying every solution I can find without any luck so far
Anything sticking out?
Yes, moving compass-rails out of :assets works but is not an ideal solution.
Checking through the output from the push to heroku I found
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
But it is compiling locally with
RAILS_ENV=production rake assets:precompile
The solution is not to instantiate the DB when precompiling assets. In config/application.rb:
config.assets.initialize_on_precompile = false
See this issue in the compass-rails project:
https://github.com/Compass/compass-rails/issues/19
I upgraded my rails to 3.2+ and ended up moving compass-rails outside of the assets group to make it work. I dont really understand why it works, but it seemed to do the trick.
I'm using the jquery-ui-rails gem. It works fine on local host, but when I push to heroku it gives heroku logs shows this:
2012-04-11T02:28:59+00:00 app[web.1]: ActionView::Template::Error (couldn't find file 'jquery.ui.slider'
2012-04-11T02:28:59+00:00 app[web.1]: (in /app/app/assets/stylesheets/application.css:12)):
My production config file:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
Some questions online say to change config.assets.compile to false, but when I do that I get a application.css not precompiled error.
Taking the line gem jquery-ui-rails out of the assets group in the Gemfile seems to help. Similar problem/fix for the twitter bootstrap gem. :)
I had a similar, though not identical, problem. In my case, drag and drop methods worked locally, but Heroku complained that it couldn't find jquery-ui.
What solved it for me was this:
In the Gemfile, added
gem 'jquery-ui-rails'
In application.js, added
//= require jquery.ui.all
In application.css, added
*= require jquery.ui.all
Finally, of course, git commit -a -m "added jquery ui statements", followed by git push heroku master.
You might have some sort of syntax error in some of your asset files. As the assets are precompiled different types of assets are concatenated as one. Now if one of your CSS files has a syntax error in the end of it, it might not affect anything in our local environment as the assets are not precompiled. However, when the asset files are joint together as one big file anything that then happens to follow the error would not get loaded. This might result in missing JavaScript stuff, CSS rules, etc..