Broken stylesheet and image paths when deploying to Heroku - ruby-on-rails

I've deployed a fresh Rails 4 app to Heroku but my stylesheets and images don't work. For the stylesheets. I use:
<%= stylesheet_link_tag "screen", media: "all" %>
For image, I use paths encoded in CSS, like:
<img class="logo small" src="/assets/logo.jpg" alt="logo">
These paths work perfectly well on my local machine but break in deployment. I thought that this is due to the not serving of static assets by the Heroku Cedar stack, and set this setting to true in production.rb:
config.serve_static_assets = false
This didn't solve it. What am I missing? Thanks!

Heroku have specific instructions for hosting Rails4 applications on Heroku. Do you have the rails_12factor gem in your Gemfile for production?
https://devcenter.heroku.com/articles/getting-started-with-rails4#heroku-gems
Also, I would suggest switching to using the rails helpers for images as it makes it easier when dealing with the asset pipeline in production -
<%= image_tag 'logo', class: 'logo small'  %>

I've figured it out - this issue was due to a badly functioning git repository. I'm using the asset pipeline now for both stylesheets and images - but I had to delete both the local git repository and the remote app and initiate everything from scratch. These are the steps I've taken:
1) Declare all stylesheets in application.css like so:
*= require_self
*= require frameless
*= require typography
*= require grid
*= require layout
(My old app used a screen.css file in which I imported the above files. This doesn't work with the AP - every file must be referenced directly in the application.css manifest file, in the correct order so as the CSS rules stack up with the right precedence. To ensure this, you might want to delete the require_tree directive that is there by default).
2) Change all HTML image paths to rails helper image_tag tags.
3) Run RAILS_ENV=production bundle exec rake assets:precompile to generate a public/assets directory with all the precompiled assets, as described here.
Check everything into a new git repository (having deleted the new), and then follow Heroku's instructions on how to deploy a Rails 4 app.
Bingo!

Related

Some assets not loading in an old Rails 3-2-stable app

BIG UPDATES AT THE BOTTOM OF THIS POST
I have a Rails 3-2-stable app that I'm moving to a new server so I can work on upgrading it to Rails 5. Currently, it's hosted on Heroku and most of the assets show up just fine (the app Just Works (TM)). I have a few random assets that will not show up after precompilation on a Digital Ocean droplet. I'm deploying with Capistrano.
The error for the assets that won't show up look something like this:
Loading failed for the <script> with source “http://stage.fancy-new-droplet.com/assets/application/application.js”.
In some cases, there will be a hash associated with the asset like this:
Loading failed for the <script> with source “http://stage.fancy-new-droplet.com/assets/application/certifications-56046476595984b00d1267a4f02822e5.js
In the former case, the asset is actually in public/assets/ as opposed to public/assets/application/ on the droplet. Moving or symlinking the missing asset to that location doesn't seem to affect anything. In the latter case, the assets just don't exist anywhere on the droplet as far as I can tell.
For the case with no hashes in filenames, changing my include tags from this:
<%= javascript_include_tag "application/application" %>
To something like this:
<%= javascript_include_tag "application" %>
Will solve the issue but I feel like that's a red herring given the other assets that don't seem to exist after precompilation.
I did run into an esoteric issue where the droplet was running out of memory and silently failing halfway through asset compilation but I increased the available memory and it doesn't even use half the memory now. It does max out the CPU 100%, though. I may try to increase both CPU and memory on the droplet.
Here are the relevant asset compilation lines from config/environments/production.rb:
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
And the relevant asset compilation lines from application.rb:
config.assets.enabled = true
config.assets.version = '1.0'
Locally, everything works 100% just peachy, no errors. Assets load fine and we're all good. Here's the asset pipeline bits from my development.rb file:
config.assets.compile = true
config.assets.compress = false
config.assets.debug = true
I've run various combinations of rake assets:clean, rake assets:precompile, and rake assets:precompile:all on the production server (in the production environment) and I've even nuked the public/assets/ folder to start it all over again. All to no avail.
What might cause these assets to not be created on our droplet while they do manage to get created on Heroku?
EDIT
As requested, my DO stack is simply just a droplet (2vcpu, 2gb ram), I'm using Puma and Nginx. Here is my Capfile:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
install_plugin Capistrano::Puma
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
FURTHER EDIT
I've frobbed config.assets.initialize_on_precompile a couple of times in application.rb and ran various permutations of rake assets:clean, assets:precompile, and assets:precompile:all with RAILS_ENV=production locally to no avail.
YET ANOTHER EDIT
I've noticed at this point that precompiling production assets seems to not be compiling four of the javascript files, and about seven of the css files. It also doesn't seem to put application.js into public/assets/application/application.js (where the app is looking), rather it lands in public/assets/application.js.
MORE EDITS
I have resolved the issue of the JavaScript assets not loading by fixing a require_tree statement in application.js and now the only issue seems to be several missing CSS files.
In this application there are two directories with css files:
app/assets/stylesheets/
app/assets/stylesheets/application
There are a total of 21 stylesheets that do not load out of nearly 100 total. The stylesheets that don't load are being called with a hashed filename (somefile-hash.css) but those hashed files don't exist in public/assets/ on the droplet.
Here's the requires from application.css.scss:
/*
*= require_self
*= require chosen
*= require jquery-ui/autocomplete
*= require jquery-ui/datepicker
*= require feature-carousel
*= require_tree .
*/
Out of frustration, I added = require_directory ./assets to that list and now I've only got about 15 stylesheets failing to compile/load. That behaviour doesn't make any sense to me as I assumed the = require_tree . would've covered the wonky subdirectory.
Individually specifying files = require foo or = require foo.css.scss does not seem to affect anything, either.
I also bumped the config.assets.version out of frustration to no avail.
And furthermore, no amount of foul language can persuade these assets to compile.
The asset pipeline concatenates your assets to only generate and serve specified files, 'application.js', 'application.css' and images/fonts by default.
If you are explicitly including other css/js files in your application via the javascript_include_tag or stylesheet_link_tag helpers, you'll need to add those files manually to the pipeline via the config.assets.precompile += setting in your application.rb or an initializer.
Currently, those files should already be included within your application manifest via the require_tree . directive. So, the styles might be being applied right now too. If that's the case, you can just remove your code that adds the individual stylesheets separately to get rid of the 404s.
Still not sure how the app is working fine on heroku, maybe you have some heroku config that's enabling serving the static assets.
Perhaps try changing these in production.rb but no guarantees, may be worth trying.
config.serve_static_files = true
config.assets.compile = false
Also if you have this in Gemfile, you might wanna try to comment it out and bundle install locally before deploy.
gem 'rails_12factor', group: :production
That 💩was required by Heroku but you may not need it on DO. See https://github.com/heroku/rails_12factor
Also, please if you can post more relevant info about your DO stack and maybe your Capfile
Just changing this on your production.rb should work:
config.serve_static_assets = true

Vendor assets not showing in heroku staging environment

my assets (i.e. css and js) in vendor folders are not showing in heroku staging environment, however, images in app/assets/images works and it also works in development environment though. I do not want to move the assets in vendors folder to the app folder because I want to keep vendor templates separate.
Below are my setup and the list of things I have tried:
app/assets/stylesheets/application.css.scss
*= require_tree .
*= require_self
*= require style.default
app/assets/stylesheets/application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery-1.11.1.min
//= require jquery-migrate-1.2.1.min
//= require jquery-ui-1.10.3.min
//= require modernizr.min
//= require bootstrap.min
//= require jquery.sparkline.min
//= require toggles.min
//= require retina.min
//= require jquery.cookies
//= require custom
//= require dashboard
//= require_tree .
config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( *.css *.js )
Ran the following command in terminal
RAILS_ENV=production rake assets:precompile
RAILS_ENV=staging rake assets:precompile
rake assets:precompile
heroku run rake assets:precompile
Results from pushing to Heroku using "git push staging master". Manifest file was detected as shown below.
remote: Bundle complete! 35 Gemfile dependencies, 85 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into ./vendor/bundle.
remote: Bundle completed (1.14s)
remote: Cleaning up the bundler cache.
remote: Detected manifest file, assuming assets were compiled locally
environments/staging.rb
config.serve_static_files = true
environments/production.rb
config.serve_static_files = true
Heroku Config
RACK_ENV: staging
RAILS_ENV: staging
GemFile
group :production do
gem 'unicorn'
gem 'rails_12factor'
gem 'pg'
gem 'heroku-deflater'
end
Rails Version
Rails 4.2.0
Ruby Version
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
Note: "config.assets.compile = true" works, but the idea is to precompile all the assets, not to rely on compile
Many thanks for taking the effort to look at my work.
UPDATE
group :production :staging do
gem 'unicorn'
gem 'rails_12factor'
gem 'pg'
gem 'heroku-deflater'
end
adding :staging to in gemfile didnt work.
config/application.rb
config.serve_static_assets = true
adding config.serve_static_assets in application.rb file didnt work..
So I further ran the following command in the staging heroku:
Rails.application.config.assets
{:_blocks=>[#<Proc:0x007fbbb0bf1558#/app/vendor/bundle/ruby/2.1.0/gems/autoprefixer-rails-5.1.8/lib/autoprefixer-rails/railtie.rb:14>, #<Proc:0x007fbbb39ac0d8#/app/vendor/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass/rails/railtie.rb:56>], :paths=>["/app/app/assets/images", "/app/app/assets/javascripts", "/app/app/assets/stylesheets", "/app/vendor/assets/fonts", "/app/vendor/assets/javascripts", "/app/vendor/assets/stylesheets", "/app/vendor/bundle/ruby/2.1.0/gems/bootstrap_form-2.2.0/app/assets/stylesheets", "/app/vendor/bundle/ruby/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts", "/app/vendor/bundle/ruby/2.1.0/gems/jquery-rails-4.0.3/vendor/assets/javascripts", "/app/vendor/bundle/ruby/2.1.0/gems/coffee-rails-4.1.0/lib/assets/javascripts"], :prefix=>"/assets", :manifest=>nil, :precompile=>[#<Proc:0x007fbbb1c00228#/app/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.2.4/lib/sprockets/railtie.rb:60 (lambda)>, /(?:\/|\\|\A)application\.(css|js)$/, "*.css", "*.js"], :version=>"1.0", :debug=>false, :compile=>false, :digest=>true, :js_compressor=>:uglifier, :css_compressor=>:sass}
Rails.application.config.assets.precompile
[#<Proc:0x007fbbb1c00228#/app/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.2.4/lib/sprockets/railtie.rb:60 (lambda)>, /(?:\/|\\|\A)application\.(css|js)$/, "*.css", "*.js"]
Also ran "heroku run rails c" then executed the following:
irb(main):002:0> puts helper.asset_path("style.default.css")
/assets/style.default-84d0516848a763e0b8b8b7005f7ae816.css
Used the following debugging method for heroku staging:
$ heroku run bash
$ ls public/assets
Output below
angular.min-4d194b7f4f12ed8eafec2d7a0c835904.js
angular.min-4d194b7f4f12ed8eafec2d7a0c835904.js.gz
animate.delay-0faaa57b808dee7f42f39ede364a56fb.css
animate.delay-0faaa57b808dee7f42f39ede364a56fb.css.gz
animate.min-fa7d9f43baff3065a44d391f5fb24dec.css
animate.min-fa7d9f43baff3065a44d391f5fb24dec.css.gz
application-30c5d5ea113f5d302dc72bac7a453e2c.js
application-30c5d5ea113f5d302dc72bac7a453e2c.js.gz
application-76133410c1e24aced49dbeb2178152ad.css
application-76133410c1e24aced49dbeb2178152ad.css.gz
basketcats-4984b24e5c745a825577436dcb5b1f7d.jpg
blogger-icon-5330825185af26ebf796626aab07992f.png
bootstrap-07c26bce6cfb4d4d3e91c2a7f3316ddd.js
bootstrap-07c26bce6cfb4d4d3e91c2a7f3316ddd.js.gz
bootstrap-datetimepicker.min-23b3c4525c36203db02c2000791bc8ee.js
bootstrap-datetimepicker.min-23b3c4525c36203db02c2000791bc8ee.js.gz
bootstrap-editable-c6281cc109e5208b5848e765b4d14da8.css
bootstrap-editable-c6281cc109e5208b5848e765b4d14da8.css.gz
bootstrap-editable.min-86d8ede345d06aca30530a7f95bb3931.js
bootstrap-editable.min-86d8ede345d06aca30530a7f95bb3931.js.gz
bootstrap-f2f6511fea58665b99245ff7db3724e8.css
bootstrap-f2f6511fea58665b99245ff7db3724e8.css.gz
bootstrap.min-237197a13514aaac49ee55c33a5ad363.css
bootstrap.min-237197a13514aaac49ee55c33a5ad363.css.gz
bootstrap.min-b0cd0a0791f795c4eb27679904b83f74.js
bootstrap.min-b0cd0a0791f795c4eb27679904b83f74.js.gz
bootstrap-override-2285f5091ba098ac5e5b620d7db3ca55.css
bootstrap-override-2285f5091ba098ac5e5b620d7db3ca55.css.gz
bootstrap-override-rtl-bdad9b2be471ec2aef1e04ac90377f0f.css
bootstrap-override-rtl-bdad9b2be471ec2aef1e04ac90377f0f.css.gz
bootstrap-rtl.min-b644011950d9b9fa31bc53f9705e829e.css
bootstrap-rtl.min-b644011950d9b9fa31bc53f9705e829e.css.gz
bootstrap-timepicker.min-92be9db07f554142043df94d011f0e92.js
bootstrap-timepicker.min-92be9db07f554142043df94d011f0e92.js.gz
bootstrap-timepicker.min-e317eaa00793dd79a1f8ef9fc3e792a9.css
bootstrap-timepicker.min-e317eaa00793dd79a1f8ef9fc3e792a9.css.gz
bootstrap-wizard.min-5a2783eaf5831f429126f8396dcda73e.js
bootstrap-wizard.min-5a2783eaf5831f429126f8396dcda73e.js.gz
bootstrap-wysihtml5-2024d0b1f3587a8af79c9375d11cbd96.css
bootstrap-wysihtml5-2024d0b1f3587a8af79c9375d11cbd96.css.gz
bootstrap-wysihtml5-845f80e90c6fe0c9944d78f7853f84c4.js
bootstrap-wysihtml5-845f80e90c6fe0c9944d78f7853f84c4.js.gz
business cat1-010151a22ba0940c53db4db068fbbb15.jpg
CatJira_logo1-347a04943f1922fa83c1e04cb9aa8d74.jpg
CatJira_logo-8b34a4e3a18a5ce98b6caf040eec0325.png
catplay-33ba713cd70738acbc11793b804789aa.jpg
charts-8dcf96513924266cccab40b5c3abd928.js
charts-8dcf96513924266cccab40b5c3abd928.js.gz
chosen.jquery.min-20f9114437b36992aa9d5a3236f3b2ee.js
chosen.jquery.min-20f9114437b36992aa9d5a3236f3b2ee.js.gz
city2-51820272cfac0a176203d69b5673f92c.jpg
codemirror
coffee-script-01f57d14cfd792fc3e4e41634619b898.js
coffee-script-01f57d14cfd792fc3e4e41634619b898.js.gz
colorpicker-274db192cab38eda2fe54fbe602aee81.js
colorpicker-274db192cab38eda2fe54fbe602aee81.js.gz
colorpicker-e8da384e85b77e601f62ec93d6517dc3.css
colorpicker-e8da384e85b77e601f62ec93d6517dc3.css.gz
creatives-398bec8370d485f61d0efbff7a47960c.jpg
custom-9bac754fb2b328db1aa727679a5333e0.js
custom-9bac754fb2b328db1aa727679a5333e0.js.gz
dashboard-387a6961818e57e508986d4fffaab4f6.js
dashboard-387a6961818e57e508986d4fffaab4f6.js.gz
dropzone-9e3f4db91b70bf7422487de2a3695678.css
dropzone-9e3f4db91b70bf7422487de2a3695678.css.gz
dropzone.min-64643fa97a6d52f7a63b1c17296ca35e.js
dropzone.min-64643fa97a6d52f7a63b1c17296ca35e.js.gz
errors-64e62ddc273c2f5847f30d698ca14b67.css
errors-64e62ddc273c2f5847f30d698ca14b67.css.gz
errors-fcec5b5a277ac7c20cc9f45a209a3bcd.js
errors-fcec5b5a277ac7c20cc9f45a209a3bcd.js.gz
facebook-icon-0d4efe4f92f6e68c8e0304ee83013016.png
favicon-f94a92edfd00b1cc38b6658933ba54fd.ico
font-awesome-7235b656c02e8e1a0af4839e29862cb0.css
font-awesome-7235b656c02e8e1a0af4839e29862cb0.css.gz
font-awesome.min-f44605a25d83e9849f7a91abbc1fa013.css
font-awesome.min-f44605a25d83e9849f7a91abbc1fa013.css.gz
font.helvetica-neue-3bee85020746eede72c4dcd3bf80bf91.css
font.helvetica-neue-3bee85020746eede72c4dcd3bf80bf91.css.gz
font.roboto-27de563886805db8510b1488e25a43ca.css
font.roboto-27de563886805db8510b1488e25a43ca.css.gz
fullcalendar-8c8f481e6c52d01d9089fb9276e301ed.css
fullcalendar-8c8f481e6c52d01d9089fb9276e301ed.css.gz
fullcalendar.min-e0e065736f355ad455f035972ee4f0f1.js
fullcalendar.min-e0e065736f355ad455f035972ee4f0f1.js.gz
gmaps-4e0a34409a72c75b23ead4560c2067ad.js
gmaps-4e0a34409a72c75b23ead4560c2067ad.js.gz
google_analytics-99bd28f02528c13b44624e84c5c90c83.js
google_analytics-99bd28f02528c13b44624e84c5c90c83.js.gz
holder-80b1ec50bf56cecf1ad3aa13205b728b.js
holder-80b1ec50bf56cecf1ad3aa13205b728b.js.gz
html5shiv-b943c98fa95fcffd9369e767949c2e8a.js
html5shiv-b943c98fa95fcffd9369e767949c2e8a.js.gz
instagram-icon-16abed513241b2885051980c313b9d47.png
jquery-1.11.1.min-89fdfdd2b961da1c1dac57e8beeff312.js
jquery-1.11.1.min-89fdfdd2b961da1c1dac57e8beeff312.js.gz
jquery2-f6430688c576903899df06242228577b.js
jquery2-f6430688c576903899df06242228577b.js.gz
jquery2.min-081439c47c59b5a03e286d1fbbd00553.js
jquery2.min-081439c47c59b5a03e286d1fbbd00553.js.gz
jquery-87424c3c19e96d4fb033c10ebe21ec40.js
jquery-87424c3c19e96d4fb033c10ebe21ec40.js.gz
jquery.autogrow-textarea-1db755051eeda2b4be077aba1883904c.js
jquery.autogrow-textarea-1db755051eeda2b4be077aba1883904c.js.gz
jquery.cookies-238dfd7d92c77c8d827e6e7df271e41d.js
jquery.cookies-238dfd7d92c77c8d827e6e7df271e41d.js.gz
jquery.datatables-2b6b927f456a60d7541726d69bd85eca.css
jquery.datatables-2b6b927f456a60d7541726d69bd85eca.css.gz
jquery.datatables.min-1f0cd1992a3aece4031123fd7fa1cb47.js
jquery.datatables.min-1f0cd1992a3aece4031123fd7fa1cb47.js.gz
jquery.gritter-d330d1b29b5213c7b69a1f4f1830419d.css
jquery.gritter-d330d1b29b5213c7b69a1f4f1830419d.css.gz
jquery.gritter.min-89110826c434b3cf1d6f58c5e7ddcb26.js
jquery.gritter.min-89110826c434b3cf1d6f58c5e7ddcb26.js.gz
jquery-jvectormap-1.2.2-b627cb9f9622cd8b2f0694578f32ea50.css
jquery-jvectormap-1.2.2-b627cb9f9622cd8b2f0694578f32ea50.css.gz
jquery-jvectormap-1.2.2.min-dd65e7b55b1b9df68da7896b0a1c77e1.js
jquery-jvectormap-1.2.2.min-dd65e7b55b1b9df68da7896b0a1c77e1.js.gz
jquery-jvectormap-us-aea-en-2118d2319e11000b32c7942e7d4b1b3e.js
jquery-jvectormap-us-aea-en-2118d2319e11000b32c7942e7d4b1b3e.js.gz
jquery-jvectormap-world-mill-en-7520a1f25b1fefbd129b81520fa33fc4.js
jquery-jvectormap-world-mill-en-7520a1f25b1fefbd129b81520fa33fc4.js.gz
jquery.maskedinput.min-f586a7257f244041eab790c5d211f37b.js
jquery.maskedinput.min-f586a7257f244041eab790c5d211f37b.js.gz
jquery-migrate-1.2.1.min-16a67272140ccc9c6aa87df04c15c468.js
jquery-migrate-1.2.1.min-16a67272140ccc9c6aa87df04c15c468.js.gz
jquery.min-eb8e576f52996bce7c557babc6e8a79e.js
jquery.min-eb8e576f52996bce7c557babc6e8a79e.js.gz
jquery.mousewheel-a78b3418946de2bdd2899b0fd7d8e009.js
jquery.mousewheel-a78b3418946de2bdd2899b0fd7d8e009.js.gz
jquery.prettyPhoto-f78f329a32e47bf51932d09c30564afa.js
jquery.prettyPhoto-f78f329a32e47bf51932d09c30564afa.js.gz
jquery.sparkline.min-639608ad39e4b3f2136934fed4dba81b.js
jquery.sparkline.min-639608ad39e4b3f2136934fed4dba81b.js.gz
jquery.tagsinput-da8da10523fb6f8ff3faf6903beb93e4.css
jquery.tagsinput-da8da10523fb6f8ff3faf6903beb93e4.css.gz
jquery.tagsinput.min-4d118b62ab063be6a215b5b26880c4fa.js
jquery.tagsinput.min-4d118b62ab063be6a215b5b26880c4fa.js.gz
jquery-ui-1.10.3-eeb57f0a91c90ebccc313b755d972670.css
jquery-ui-1.10.3-eeb57f0a91c90ebccc313b755d972670.css.gz
jquery-ui-1.10.3.min-8ff0c79f1466addcf6bf4aaf666799c8.js
jquery-ui-1.10.3.min-8ff0c79f1466addcf6bf4aaf666799c8.js.gz
jquery.ui.touch-punch.min-0062e10ac0b77dac44049f0b244a1343.js
jquery.ui.touch-punch.min-0062e10ac0b77dac44049f0b244a1343.js.gz
jquery_ujs-e27bd20a10d28155845a22d71ef94f2f.js
jquery_ujs-e27bd20a10d28155845a22d71ef94f2f.js.gz
jquery.validate.min-cc10e387641dc3a427c0b2a1d6a5cc08.js
jquery.validate.min-cc10e387641dc3a427c0b2a1d6a5cc08.js.gz
lato-9eab93d341daca0b64eb83e500c36c7d.css
lato-9eab93d341daca0b64eb83e500c36c7d.css.gz
Lookupkitten1-inverted-468ad96030a9c7c555a9e598eec25705.jpg
manifest-75f18e2d98f206cfb74b04585af62025.json
masonry.pkgd.min-39a9db9644583f39a4afc5245d1a7b48.js
masonry.pkgd.min-39a9db9644583f39a4afc5245d1a7b48.js.gz
modernizr.min-e85e2cf3694aba170e11bb364d4f38c8.js
modernizr.min-e85e2cf3694aba170e11bb364d4f38c8.js.gz
moment-1e5ae5b0dd501d933da017e415e6658d.js
moment-1e5ae5b0dd501d933da017e415e6658d.js.gz
morris-b2de433af8eec1719536e9b00c3d78cd.css
morris-b2de433af8eec1719536e9b00c3d78cd.css.gz
morris.min-544a2438115ee60523b71a1a99f94e34.js
morris.min-544a2438115ee60523b71a1a99f94e34.js.gz
pinterest-icon-0738f59cb68a09fbe0387c25b94cfe91.png
prettyPhoto-b0211d39e61dd455b051e9df2100c166.css
prettyPhoto-b0211d39e61dd455b051e9df2100c166.css.gz
publishing2-88893fd664cca1fb36e83ef0b1f05707.jpg
rails_bootstrap_forms-85a44da0cf14906976bde10ea0a42bbc.css
rails_bootstrap_forms-85a44da0cf14906976bde10ea0a42bbc.css.gz
raphael-2.1.0.min-7f08beb5a8d60af0dff9d34187bae9a9.js
raphael-2.1.0.min-7f08beb5a8d60af0dff9d34187bae9a9.js.gz
respond.min-943d23379ec213cd5fac370c1407a384.js
respond.min-943d23379ec213cd5fac370c1407a384.js.gz
retina.min-0a2f559b265ead424c27ab96d85d0b27.js
retina.min-0a2f559b265ead424c27ab96d85d0b27.js.gz
roboto
roboto-c2c7202e06866f7695a402846d6fc487.css
roboto-c2c7202e06866f7695a402846d6fc487.css.gz
select2-b4679ffd84b4af1e00b5e2f63c909de1.css
select2-b4679ffd84b4af1e00b5e2f63c909de1.css.gz
select2.min-dc009a4312724dfd32e04dc84c7cc822.js
select2.min-dc009a4312724dfd32e04dc84c7cc822.js.gz
style.bluenav-eef27f15d23db5d20d1fa45aacfb6c4a.css
style.bluenav-eef27f15d23db5d20d1fa45aacfb6c4a.css.gz
style.darkknight-41adb57795102ac40409822f26a389a8.css
style.darkknight-41adb57795102ac40409822f26a389a8.css.gz
style.default-84d0516848a763e0b8b8b7005f7ae816.css
style.default-84d0516848a763e0b8b8b7005f7ae816.css.gz
style.default-rtl-fe345a8404e132c62dba693b02debd84.css
style.default-rtl-fe345a8404e132c62dba693b02debd84.css.gz
style.dodgerblue-c3b44311e0db6c2ab5ea0c6bebd550da.css
style.dodgerblue-c3b44311e0db6c2ab5ea0c6bebd550da.css.gz
style.greyjoy-25f81d84ba89347d264f4aa2b84dbdbd.css
style.greyjoy-25f81d84ba89347d264f4aa2b84dbdbd.css.gz
style.inverse-ec1a47cdc185e55472a8115af3d99a8d.css
style.inverse-ec1a47cdc185e55472a8115af3d99a8d.css.gz
style.katniss-ccdda17b7614d5093fcf61465ae8aa9d.css
style.katniss-ccdda17b7614d5093fcf61465ae8aa9d.css.gz
toggles-428ccce58542ffa3ba9c1d3cfe253d36.css
toggles-428ccce58542ffa3ba9c1d3cfe253d36.css.gz
toggles.min-fea21bf806ff8388d5a8ad6ecd67fb47.js
toggles.min-fea21bf806ff8388d5a8ad6ecd67fb47.js.gz
tumblr-icon-6c8ddc711d5f3f9dc2e163268fc282c4.png
turbolinks-f87b3583ca50adb0488b031297f5580d.js
turbolinks-f87b3583ca50adb0488b031297f5580d.js.gz
twitter-icon-e96caf41d7a48f88f48a2e25e74e07d8.png
visitors-f2c7b5fd67318e31b093b301ddb1b606.js
visitors-f2c7b5fd67318e31b093b301ddb1b606.js.gz
weather-icons.min-463072e65eba39f9c8908b334705937e.css
weather-icons.min-463072e65eba39f9c8908b334705937e.css.gz
wordpress-icon-707488a657e1f5e8c018b0b2335d37ca.png
wysihtml5-0.3.0.min-d70870a054c85cf85d1d8ec0adc94935.js
wysihtml5-0.3.0.min-d70870a054c85cf85d1d8ec0adc94935.js.gz
wysiwyg-color-db6d982825da1878a5b105a812ba227e.css
wysiwyg-color-db6d982825da1878a5b105a812ba227e.css.gz
youtube-icon-e0a4bd918821ef87fc2f9410c9d1054a.png
I am not sure if you saw this page, but I had similar issue and this helped me out.
I would check to make sure you have config.serve_static_assets = true in your config/application.rb
If you do I would skip down to the debugging section
So after some trial and error and getting feedback, below are some take away that I hope can help others in the future. The short of it is that, if you face any problem, always refer to Rails Asset Pipeline. This is because different rails versions has different methods. At the point of this answer, mine is Rails Version: Rails 4.2.0. Ruby Version: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
Do note that this answer applied to my situation, may vary with yours.
My Problem Statement:
I bought a bootstrap template online and would like to incorporate it to my application. Below are the following steps I took to resolve the problem.
Put files into vendor/assets - I cut and paste all the templates into my vendors/assets folder. All of the assets are properly arranged into their respective fonts folders, images folders, javascript folders and stylesheets folder.
Only keep what I need - I removed the files that I do not need and only keep those that I need. This requires some reading of the vendor files.
Ensure correct assets path - after which I went through each each files and ensure that the files are referencing the assets correctly. Any css files that has image and font references, I changed it to css.erb format, then put <%= asset_path(...) %> into url(...). Note that there are various ways to do this i.e. use font_path or image_path, use css.scss instead of css.erb etc. Please refer to documentation from asset pipeline. I also removed any #import url('<your file>.css'); cause I will be using *= require <your files> later
Config application.js and application.css in app/assets - I then key in "require " into application.js and application.css manifest respectively based on the names of the files I have in my vendor/assets folder. D note that the order is important. The manifest reads from top to bottom. Therefore, always ensure pre-requisite files are kept above files that depends on it. For example, I have a default.css file that depends on font.css, hence *= require font.css comes before *= require default.css.
Create your view - then I created a some html.erb views files with controllers and routes.
Test development locally - Launch the app locally through rails s. If you put the files correctly in their respective folders in vendor/assets. Your application should show up nicely. Else, please refer to the instructions above and try again.
Config to test production locally - to test production locally, first, go to your secrets.yml file and change the production secret_key_base to the one secret_key_base from your development (IMPORTANT to revert this back to ENV once you are done testing),
Precompile and open rails app in production locally - Once you have configured, run RAILS_ENV=production rake assets:precompilein the
terminal. You should see your assets being precompiled. Once the
precompile is done, you should be able to find an assets folder in
your public folder (your images, videos and fonts assets should each
have their own files, whilst all css and js will be cramped into one file as application-<md5>.css and application-<md5>.js respectively). If this didnt workout properly, your precompile fails. It is most probably due to css or
js syntax error, go back and check the files and make the changes.
If you have made any corrective changes, please run rake assets:clobber to remove the public/assets then run the production precompile again. Once all is good, run the following command in your terminal rails s -e production, this
opens up your server locally but in production environment instead
of dev environment. When running localhost:3000 if your secret_key_base is not copied properly, you will see an error in your browser asking you to make changes to the secret key.
Viewing localhost:3000 in browser - If your view in local production is different from that of your local development view. For example, most of the css did not show up properly, troubleshoot by
right click on the parts of the website that is not reflected properly, click on inspect element, you should be able to see 404 errors. this means that your code or assets in .css and .js is not referenced or configured properly. go back to point 8 and redo.
check your rails server logs to find if there are any ActionController::RoutingError (No route matches [GET] "/assets/.... this means that your code or assets in .css and .js is not referenced or configured properly. go back to point 8 and redo.
Pushing to heroku - Once everything is good locally, you can now push to heroku. because you ran the precompile for production env locally, you will see that during your push to heroku, heroku will state something like remote: Detected manifest file, assuming assets were compiled locally. else, heroku will have to precompile for you. Note that heroku use rails_12factor gem in production. Additionally, these gems, sass-rails, coffee-rails, uglifier, come in default when you created your rails app which is essential for your asset pipeline.
Things I did not do to resolve my problem:
Though the methods below are valid,
I DID NOT use config.serve_static_assets = true for application.rb, production.rb or staging.rb
I DID NOT ran rake assets:precompile
I DID NOT ran heroku run rake assets:precompile
I DID NOT put Rails.application.config.assets.precompile += %w( *.css *.js ) in config/initializers/assets.rb
I DID NOT resort to using config.assets.compile = true
I DID NOT use config.assets.paths << Rails.root.join("lib", "videoplayer", "flash") in config/application.rb
Other links that could be helpful:
No route matches [GET] /assets
https://github.com/FortAwesome/font-awesome-sass/issues/48
Things I could not explain
This solution only worked when I recreated a new rails app. My old rails app did not work as when I ran precompile, the css and js files in public/assets were not in one application-<md5>.css and application-<md5>.js respectively. instead, they were scattered to their own font.css, default.css etc etc, as seen from "Output below" shown above. Will be doing more research to get down to the bottom of this.
I hope my answer above helped. Do give feedback if I made any mistakes or missed out anything.
Adding the vendor asset to precompile in assets.rb (f.e. Rails.application.config.assets.precompile += %w( highcharts.js ) worked form me, when deploying to Heroku. (and I didn't use a joker like *.js)

Rails assets not precompiling in production

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?
this is because things work differently in development as compared to production.
few thing to note:-
No CSS or JS files will be available to your app through the asset pipeline unless they are included in other files OR listed in the config.precompile directive.Only application.css and application.js are available by default of all the CSS and JS files.
Every file that is not a Javascript file or CSS file that is in the app/assets folder will be copied by Rails into the 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
for 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
Run RAILS_ENV=production rake assets:clean assets:precompile
check public/assets directory and verify that assets are compiled..if its not empty...that means asset pipeline is working but path is not correct.use asset_helpers to set the path of assets in css files.

Heroku does not load assets from asset pipeline

In my Rails app I have css and js that is unique to each action.
So users#new has its own css. It's named users_new.css.scss.
I deployed my app to Heroku, and Heroku isn't loading any of the assets. You can see the errors here. How do I fix this so Heroku correctly precompiles and loads the assets?
I read through Heroku's docs on using the asset pipeline, but didn't see any solution.
Precompilation
The problem is your timelines_index.js is not precompiled:
The way you can tell this is a problem is that when you call the asset in your layout (which I presume you're doing with the correct path helpers), Rails will automatically reference the latest precompiled version of that file (hence why application.js has the appended MD5 fingerprint)
I believe you'll need to add your custom files to your precompiled_assets array:
#config/environments/production.rb
Rails.application.config.assets.precompile += ['timelines_index.js']
This will give Rails the ability to precompile those assets individually, allowing you to call them in your layout:
#app/views/layouts/application.html.erb
<%= javascript_include_tag "timelines_index" %>
This will have to be done for all the custom asset files you wish to call in your layout.
Manifest
As mentioned by Anil, you may wish to use the manifest system of Rails to concatenate all your asset files into their respective application files.
This will quash the need to append the files to the Rails precompile array, allowing you to call a single file for your various assets:
#app/assets/javascripts/application.js
//= require_tree .
Add in your Gemfile
gem 'rails_12factor', group: :production

asset:precompile for .js files? rails 3.1

Question:
How do you get the asset pipeline to process all your .js files? (I want them served individually, not bundled into application.js)
I'm getting a ton of 404's for the javascript files that my pages are trying to reference:
GET http://<myStagingServer>.heroku.com/assets/<javascriptFilename1_MD5fingerprint> 404 (Not Found)
GET http://<myStagingServer>.heroku.com/assets/<SubDir>/<javascriptFilename2_MD5fingerprint> 404 (Not Found)
I tried adding this to config/application.rb:
config.assets.precompile << '*.js'
But that didn't do anything as far as I can tell.
Background:
I'm upgrading from Rails 3.0 to 3.1 and enabling the asset pipeline.
Highlights so far:
Switching to Heroku's Cedar stack from Bamboo: heroku create --stack cedar.
Switching to "thin" as the production server, which fixed various issues: gem 'thin'.
Moving my assets from public/assets to app/assets, updating references in code to use stylesheet_link_tag and javascript_include_tag. (Plus whatever I did for images -- they work.)
Removing x_sendfile_header config options because Heroku doesn't support it.
Relevant files:
//
// application.js
//
//= require_self
//
OMG: I found the problem:
javascripts and stylesheets with periods in their names require explicit extensions
For example:
# WORKS
javascript_include_tag "application"
stylesheet_link_tag "application"
# BROKEN
javascript_include_tag "jueryui.custom"
stylesheet_link_tag "jueryui.custom"
# WORKS
javascript_include_tag "jueryui.custom.js"
stylesheet_link_tag "jueryui.custom.css"
I guess I can see why this is, but I think that it isn't very well documented on any of the asset pipeline tutorials. Is it common knowledge that you shouldn't have periods in your asset filenames?
I think you need the following in both application.js and application.css :
//= require_tree .
This loads all the files in the assets directory for CSS and JS.
Also for upgrading to 3.1 and info on the asset pipeline:
http://railscasts.com/episodes?utf8=✓&search=Asset+pipeline
Also: Using Rails 3.1 assets pipeline to conditionally use certain css

Resources