An application error constantly occurs:
2014-11-26T06:45:10.349830+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
In my application.html I have:
<%= stylesheet_link_tag "application" %>
In my production.rb, because heroku is not serving and the application should serve static assets I have:
config.serve_static_assets = true
config.assets.compile = true
On the live site I have:
<link href="/assets/application-da7e0e08bb87fbae6f1225fa189fab8e.css" media="screen" rel="stylesheet" type="text/css" />
The url
mysite/assets/application-da7e0e08bb87fbae6f1225fa189fab8e.css
returns a result.
The url
mysite/assets/application.css
also returns a result.
Everything is working fine, but there is this error message in the log and I can not understand why. Who requests /stylesheets/application.css and why and how to stop this error from occurring.
Rails is "3.2.16"
There should be two problems:
1) add %<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>>
2) It looks like you have added assets precompiled file in your git repo. Ideally, it shouldn't be there since heroku can this for you whenever you push it.
To fix this, you have to do this
git rm -r public/assets/
add public/assets/** in your .gitignore file
git add .
git commit -am "allow heroku auto assets precompilation"
5.git push heroku master
Related
I'm stumped. I have a vanilla install of Rails 5 running within docker yet I'm constantly getting this error:
Request ran for longer than 5000ms
All I've done so far was generate a new controller with docker-compose run website rails g controller pages.
So far, if I remove (very important) lines from layouts/application.html.erb, I can get the page to load:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
But I loose all my default styling (bootstrap) and any potential javascript files I wish to load later in life, which I do not consider to be a fix.
Anyone else run into this problem and know how to fix it?
#JimmyBaker answered in the comments
Try setting config.assets.debug to false
Inside config/development.rb
config.assets.debug = false
Having this set to false will cause all CSS & JS to be bundled into application.css or application.js More on assets.debug
I'm running the latest version of Thin, Rails, and Ruby. The relevant parts of my build script are:
export RAILS_ENV=production
export RAILS_SERVE_STATIC_FILES=true
# generate static assets
RAILS_ENV=production rake assets:precompile
# restart server
rails server thin -d
And in my production.rb I have
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
And I include these files in my view using
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
This successfully compiles my assets and moves them to the /public/assets folder. However, none of these assets are actually served when loading the page. The generated HTML is
<link rel="stylesheet" media="all" href="/stylesheets/application.css" />
<script src="/javascripts/application.js"></script>
These don't have the digests included in the filename, so I believe they're incorrect. Attempting to manually load the filenames both with and without their digest included all fail with a 404 as well. What am I doing wrong?
put the js files under app/assets/javascript.
put the css files under app/assets/stylesheets.
All your js and css files are loaded in the header of application.html.erb, which loads the application.css and application.js. This is what these two lines of code does.
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
These two files, there is a line require_tree . which loads all the files in the corresponding directory:
app/assets/javascript
app/assets/stylesheets
I usually use public folder only for external libraries when I am not using a CDN. And you will need to explicitly include them in the application.js and application.css file.
I am attempting to get a Rails 4 application running with RAILS_ENV=production.
My objective is to precompile assets and use a CDN to serve them quickly.
What I have done so far
production.rb
config.serve_static_assets = false
config.action_controller.asset_host = "http://mycdn.cloudfront.net"
config.assets.js_compressor = :uglifier
config.assets.compile = false
Precompile step that runs correctly during opsworks deploy
"/usr/local/bin/bundle exec rake assets:precompile"
Output From Precompile
/srv/www/myapp/current/public/assets/$ ls
application-<digest>.css
application-<digest>.js
... other images, etc...
Using rails helper tags for .js and .css in /application.html.slim
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= favicon_link_tag 'favicon.png'
What did I expect
On page load I would see things like (expected digest in url):
<link data-turbolinks-track="true" href="http://mycdn.cloudfront.net/stylesheets/application-<digest>.css" media="all" rel="stylesheet" />
What actually happens
On page load I see things like (NO DIGEST in url!):
The bad news is they are missing, since application.css doesnt exist anywhere in my app, the CDN cant cache it, naturally.
<link data-turbolinks-track="true" href="http://mycdn.cloudfront.net/stylesheets/application.css" media="all" rel="stylesheet" />
Any help would be much appreciated.
Random stats:
- Rails 4.1.5
- Unicorn 4.8.1
- Opswork stack as my deploy target
- Cloudfront as my CDN
You need to add this to your production.rb file ( and any other environnent that you want to have digests in )
config.assets.digest = true
I have seen lots of posts regarding precompiled assets in rails, but I don't think I see one that is related to my specific problem.
My application is complaining that aplication.css.scss is not precompiled.
From what I understand, any *.scss file should be compiled in my rails application when i run:
rake assets:precompile
I even confirmed in my public/assets folder that I can see the compiled application.css file.
However, when I try to visit the first page of my application I get the following error:
Compiled application.css (1002ms) (pid 20298)
Started GET "/" for 10.20.1.162 at 2013-01-21 12:21:38 -0500
Processing by MyController#new as HTML
Rendered business_searches/partials/_form.html.erb (16.6ms)
Rendered business_searches/new.html.erb within layouts/application (45.6ms)
Rendered commons/_documenthead.html.erb (34.0ms)
Completed 500 Internal Server Error in 139ms
ActionView::Template::Error (application.css.scss isn't precompiled):
4: <meta charset="utf-8" />
5: <title>My Company Name | <%= #page_title || 'My Company Tagline' %></title>
6:
7: <%= stylesheet_link_tag "application.css.scss", :media => "all" %>
8: <%= javascript_include_tag "application" %>
9:
10:
app/views/commons/_documenthead.html.erb:7:in `_app_views_commons__documenthead_html_erb___1078677729313377561_30352020'
app/views/layouts/application.html.erb:1:in `_app_views_layouts_application_html_erb___646383708034639720_28260100'
I was able to fix the problem by setting the following variable in my config/environments/production.rb file:
config.assets.compile = true
But according to this post, that is not recommended.
I would advice you to keep your manifest file application.css just for managing css assets , and not to prefix it with .scss . The correct syntax for application.html.erb file is :
<%= stylesheet_link_tag "application", :media => "all" %>
If you've placed some styles in your 'application.css, just create a newcss.scssfile in yourapp/assets/stylesheets` and place them there .
It's because your scss file is having a compile time error. I am quite sure that if you replace it's contents with known valid ones, it will get compiled.
You may comment it and check if it compiles.
Always use 'application.CSS' as base CSS.
Others should be separate.
I've been following along Michael Hartl's excellent RoR Tutorial, but I'm using RoR 3.1. I am a newbie to RoR 3.1 and need help related to assets pipeline. Here is my problem:
Before continuing to section 5.3, I thought I'd like to push to Heroku and see how things develop. To my surprise "GET /" results in error 500. Everything went OK in my local-development-environment. I then tried running my local sample_app under production-environment (rails s -e production). Same result, error 500:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Pages#home
Showing /Users/john/Projects/sample_app/app/views/layouts/_stylesheets.html.erb where line #4 raised:
blueprint/screen.css isn't precompiled
Supporting info:
I put blueprint CSS directory under vendor/assets/stylesheets.
I followed Michael's section 13.1.4 advice and have the following as my app/views/layouts/application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<%= render 'layouts/stylesheets' %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="container">
<%= render 'layouts/header' %>
<section class="round">
<%= yield %>
</section>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
Content of app/views/layouts/_stylesheets.html.erb:
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
<!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
I have run bundle exec rake assets:precompile.
Content of public/assets/manifest.yml:
---
logo.png: logo-8e0a5ad292fbb13a2b07e68fa3995406.png
rails.png: rails-bd9ad5a560b5a3a7be0808c5cd76a798.png
blueprint/plugins/buttons/icons/cross.png: blueprint/plugins/buttons/icons/cross-2ebcd25368006d1b7b0c5b7d6b523ab3.png
blueprint/plugins/buttons/icons/key.png: blueprint/plugins/buttons/icons/key-55237526967cbcab3e8cfb12f0029d88.png
blueprint/plugins/buttons/icons/tick.png: blueprint/plugins/buttons/icons/tick-3f5fc1f52b505b93f88263e0432d25ce.png
blueprint/plugins/buttons/readme.txt: blueprint/plugins/buttons/readme-3ff7f5dbb0288d71f70682fdbe9d86ec.txt
blueprint/plugins/fancy-type/readme.txt: blueprint/plugins/fancy-type/readme-e7ed185d1a9f23256d418ab929b464d9.txt
blueprint/plugins/link-icons/icons/doc.png: blueprint/plugins/link-icons/icons/doc-b071fd74b88ff38cda8360a53f493013.png
blueprint/plugins/link-icons/icons/email.png: blueprint/plugins/link-icons/icons/email-28104e72b3418737d4b9b329c12ec358.png
blueprint/plugins/link-icons/icons/external.png: blueprint/plugins/link-icons/icons/external-ee6d976ddb80125fafe1a33c6f8aed10.png
blueprint/plugins/link-icons/icons/feed.png: blueprint/plugins/link-icons/icons/feed-59bc8604661681639d25cb7015a32c38.png
blueprint/plugins/link-icons/icons/im.png: blueprint/plugins/link-icons/icons/im-afeeb6e0b652c1edb1441bf0fb428596.png
blueprint/plugins/link-icons/icons/lock.png: blueprint/plugins/link-icons/icons/lock-d73c4b3b57ce72cb6dbd8b265507ff75.png
blueprint/plugins/link-icons/icons/pdf.png: blueprint/plugins/link-icons/icons/pdf-c4c543e5103a8516839a7846b91e1ac4.png
blueprint/plugins/link-icons/icons/visited.png: blueprint/plugins/link-icons/icons/visited-fb2370448bc4ea5d079e963a8c0d900b.png
blueprint/plugins/link-icons/icons/xls.png: blueprint/plugins/link-icons/icons/xls-5399729cd31dffc492a04b3805cd0be1.png
blueprint/plugins/link-icons/readme.txt: blueprint/plugins/link-icons/readme-42c02030199cd36a671d4b623cb4dc36.txt
blueprint/plugins/rtl/readme.txt: blueprint/plugins/rtl/readme-8d11bf76e19fb3fc7dbc6c2ddb54b92d.txt
blueprint/src/grid.png: blueprint/src/grid-973add038ed86febca85f03e8b35b94a.png
jquery-ui.min.js: jquery-ui-7e33882a28fc84ad0e0e47e46cbf901c.min.js
jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js
application.js: application-a552e1db33b8be6a42eedf1261916f3c.js
application.css: application-214e0c0742f20b334e8a7776e0a4c71d.css
I don't see blueprint/screen.css in manifest.yml.
What am I missing?
From http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array
This means that in your config/environments/production.rb, you set
config.assets.precompile += %w( blueprint/screen.css blueprint/print.css )
or a catchall:
config.assets.precompile += %w( *.css *.js )
I added a reference to the blueprint stylesheets in my application.css file. This way, I do not have to change the layout to modify the stylesheets, I simply need to modify the application.css file, run rake assets:precompile, and restart the webserver (if webrick or similar).
My application.css currently looks like this:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree ./blueprint
*= require_tree .
*/
You may want to precompile your assets on production as described above.
And if you use capistrano you may do it after code update:
require 'bundler/capistrano'
after 'deploy:update_code' do
run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
end
From my own experience with this problem, where I was also going through the excellent RoR tutorial by Michael Hartl, there was one step that I think might be left out at this point...
bundle exec rake assets:precompile
git add public/assets
git commit -m "vendor compiled assets"
git push heroku
I found this here.