Rails 3.1 Asset Pipeline Fingerprinting - css

Simple question:
I've got a Rails 3.1 app running in staging, which is RAILS_ENV=production. My problem is this: stylesheet_link_tag produces a different fingerprint for my css files than the fingerprint that was produced by rake assets:precompile.
So when I request a page, the link to the stylesheet is looking for a file like:
/assets/front-1e3a4454e0d5434eccac1a053ca4c7fd.css
but in reality the file sitting in public/assets is
front-60b624d69d97b3ac5f288c54245a5ed5.css
and the browser returns a 404 Not Found.
Here is my linlk stylesheet_link_tag :front. Can anybody explain to me why this happens?

I've been having the same exact issue. Best I can tell, this occurs when the precompile task runs during a capistrano deploy. I've had to remove the precompile from deployment and run the
rake assets:precompile RAILS_ENV=production from the release directory after the app has been deployed. It's a pain if you're pushing code frequently.

Related

RoR App: "The asset 'application.css' is not present in the asset pipeline" after moving to production server

after moving my Ruby on Rails app to production server (AWS EC2 Amazon Linux 2018.03) pages don't render, because of error "The asset 'application.css' is not present in the asset pipeline" (precompiled files are presents in public/assets):
production.log
However, when I refresh my application (sometimes more then once), this file is found in cache and page is rendering correctly. It seems like server doesn't wait for file precompilation or something like that. It happens not only on first page entry, but every change of view.
I followed tips from post:
application.css not in asset pipeline, but it didn't help.
My stack:
ruby 2.6.3
rails 5.2.3
Unicorn 5.5.1
nginx 1.14.1
I will be really grateful for any hints.
You can confirm your app/assets/stylesheets folder it should have application.css file and you will have to precompile assets in production environment before go/start server in production environment.
You can precompile assets using
RAILS_ENV=production rails assets:precompile
If it still does not work then you can try the config.assets.compile option to true in production.rb so it will do live compilation. Although it should be false in production environment as it impact on performance.
config.assets.compile = true
I had this problem on a GitHub Action workflow, and adding this line fixed it:
bundle exec rake assets:precompile
Example
run: |
bundle exec rails db:prepare
bundle exec rake assets:precompile # <--- here

Cant get heroku to link to my asset js/css in my rails app

I'ved recently deployed my app on heroku, but for some reason, my scripts and css are not linked properly. In local there is no problem.
This is basically how I render my scripts and css in the view:
<%= javascript_include_tag "welcome_page_scripts" %>
<%= stylesheet_link_tag "welcome_page_styles" %>
I'ved put these js/css files into vendor/javascripts or vendor/stylesheets directory.
In my production.rb:
config.serve_static_assets = false
config.assets.compile = false
I tried to set either one to true, and perform the following but still does not work.
rake assets:precompile --trace RAILS_ENV=production
Update 1:
(I noticed I also already have this in my Gemfile). Still the asset links not working on Heroku but works on local.
gem 'rails_12factor', group: :production
Can someone give me the right direction on how to solve this. Thanks.
Did you remember to commit to git after you did the precompile (git add public/assets), and commit those changes to Heroku (git push heroku master), since the precompile creates a manifest.yml file in public/assets? More info here: https://devcenter.heroku.com/articles/rails-asset-pipeline
Heroku provides a gem for that. https://github.com/heroku/rails_12factor
If you don't want to use it, then going through issues in that page can be helpful

Removed Stylesheet from application but it still appears on Heroku

I remove a stylesheet that contained media queries for specific devices. The changes appear on my local version. When I view it in production on heroku the media queries are still there. I asset removed it from the assets initializer # Rails.application.config.assets.precompile += %w( apps.css ). I ran heroku run assets:clean and restarted the server but it still remains. git status shows that there are not uncommitted changes.
You will have to do a couple of more steps:
$ rake assets:precompile
$ git add .
$ git commit
... deploy to heroku
rake assets:clean just removes the compiled assets locally; without running the precompile step to generate new assets, the assets on heroku does not get refreshed.

rake assets:precompile bug with rails and compass and "*"

I use rails 4.2.0 and compass-rails (2.0.2)
I have a css.scss file with
#import "compass/utilities/sprites";
#import "icons/*.png";
#include all-icons-sprites(true);
I have many image .png in app/assets/images/icons/XXX.png
I want deploy my app in production, it's work but with no assets, so I start
rake assets:precompile
in production environement.
An error occure:
rake aborted!
Sprockets::FileNotFound: couldn't find file 'icons/*.png'
I try to remove assets files in cache, nothing change.
details error: http://pastebin.com/6ggS3pP2
I think there is a problem with wildcard and path.
I try in dev ENV, nothing change...
I don't know what do more, what's the solution, plz?
to fix it, I just use mster branch of git like :
gem 'compass-rails', github: 'Compass/compass-rails'

Assetic dump uses same tmp folder for different Symfony2 projects

I've the following environment: One Apache2 Webserver on an Ubuntu machine with three vhosts (one vhost per project). Those three project run all on Symfony2 (but differnt versions, from 2.2 to 2.4). Each of the projects (and its paths) have an own user. I'm deploying the projects with capifony on this server, each has an own receipt.
Sass version
Sass 3.2.14 (Media Mark)
Imagine I'm deploying application 1 to the Webserver. When the deploymentprocess comes to dumping all production assets, its writing the temporary generated sass files into the following folder:
/tmp/600d657f6ac2358f30ba6bc0ab4cd7ffb6194ced
as user1.
If I'm deploying now application 2 to the Webserver, dumping the assets would like to write into the exactly same folder, this time as user2 and the following error occurs:
An error occurred while running:
* [err :: 10.0.106.103] '/usr/bin/ruby' '/usr/local/bin/sass' '--load-path' '/srv/vhosts/myproject.com/releases/20140619124055/app/../web/sass' '--scss' '--cache-location' '/tmp' '/tmp/assetic_sassbsrcle'
* [err :: 10.0.106.103]
* [err :: 10.0.106.103] Error Output:
Errno::ENOENT: No such file or directory - /tmp/600d657f6ac2358f30ba6bc0ab4cd7ffb6194ced/assetic_sassbsrclec20140619-27927-aw8xrk.lock
My workaround currently is, to remove this /tmp/600d657f6ac2358f30ba6bc0ab4cd7ffb6194ced folder every time before deployment.
I didn't find any pathconfiguration in the capifony receipts nor in the Symfony2 config files in all projects.
Any help is appreciated.
Best,
Ramo
This has been referenced on the official assetic repository as an issue, as well. Since you can set sys_get_temp_dir() via the environment variable TMPDIR (among others), I would recommend doing that for your dump. You could base it off the current unix time, or the commit you're deploying, or a combination of the application, time, and intent. Really, anything could work. The line responsible for setting the cache location is here, in case you wanted to fork Assetic and change that, which is quite doable as well. I would suggest the TMPDIR route at first to confirm a potential fix.
Small edit, there is also this pull to semi-address this issue.

Resources