Rollback rake assets:precompile - ruby-on-rails

I operate Rails 3.2.13 and I ran a
rake assets:precompile
In order to activate some CoffeeScript that wouldn't fire otherwise,
and it completely ruined my pages layout, which was fine until then.
The menu of my application is now vertical instead of horizontal and the rest of the pages is subsequently invisible.
I use Bootstrap and I suspect this has been updated, for some reason, but it's too much work to change it, if I only knew why it has changed and what has changed anyway...
I would like to go back to the former state of my layout.
Is there any way to roll back ?

remove public/assets
explanation:
the precompile task compiles your assets, usually in app/assets, and places them in your public folder/assets folder.
If you want to go back to the state prior to the precompile, just remove public/assets
rm -fr public/assets.

I had this problem too. In addition to removing the precompiled assets under the public folder, I also had to clear the tmp/cache folder.

ok, this should be the problem: you changed your bootstrap version from 2.1 to 3.1 and the syntax you're using is not suitable for 3.1.
That's not a question of compiling assets, just that from version 2 to version 3, there's a totally new syntax.
Have a look here:
http://getbootstrap.com/migration/
Then set your bootstrap gem version to 2.1 in your gemfile and run bundle install. Everything should go back to the right place.

Related

After upgrading to new Rails version few images are broken

So my company updated Rails and Ruby versions, after that only few images became broken. They all defined in scss with image_url("frontend/image_title.png"), but only like 4 of them aren't showing anymore, server gives 404 error.
All of them used as a background images.
What could be a problem and a solution?
Have you tried precompiling the assets ?
The call too image_url is done once during precompilation of assets so it could be that the assets in production still have old paths.
To precompile run the following command:
bundle exec rake assets:precompile
Looks like i will always answer my own questions :)
The problem was that there are few .scss files that was compiling with assets pipeline, and those .scss files had some same code, like scss variables and reset code, which i decided to move out of them to separate file, called reset.css.scss and import that file into those .scss files with #import function, which works bad with Rails *= require methods.
After moving that code back to .scss files and removing the #import stuff, everything worked fine.

Sass::SyntaxError when using Bootstrap in Rails application on Heroku

I installed twitter bootstrap by copying the files into my assets directory as per the instructions here: http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/
After following the instructions exactly as presented and executing "rake assets:precompile RAILS_ENV=development", I am able to use bootstrap 3 in my development rails server.
However, when I try to execute "heroku run rake assets:precompile RAILS_ENV=production", I get this error:
Sass::SyntaxError: Invalid CSS after "...ss","sources":[": expected "|",
was ""less/theme.les..." (in /app/app/assets/stylesheets/application.css) (sass):444
I am not sure what this means. When I open "application.css" in the assets/stylesheets folder, I can't even find a line 444. I do have some scaffold files left over after running "rails g scaffold ..." commands -- could that be causing this problem? And obviously, the deployed heroku app looks like a non-bootstrap app when I view it from the heroku page and throws a "resource not found" error.
In public/assets/application-mydigest.ccs, I found the following line of code that causes the error:
{"version":3,"file":"bootstrap-theme.css","sources":["less/theme.less","less/mixins/vendor-prefixes.less","bootstrap-theme.css","less/mixins/gradients.less","less/mixins/reset-filter.less"],"names":[],"mappings":"AAeA;;;;;;EAME,0CAAA;EC+CA,6FAAA;EACQ,qFAAA;EC5DT;AFiBC;;;;;;;;;;;;EC0CA,0DAAA;EACQ,kDAAA;EC7CT;AFqCC;;EAEE,wBAAA;EEnCH;AFwCD;EG/CI,0EAAA;EACA,qEAAA
However, it seems odd that this would only happen on production. Moreover, the CSS syntax looks fine.
This error means the assets compilation failed because of an invalid css syntax into a file you require in application.css.
In bootstrap repository there is a less directory and you can't precompile less files with rails.
If you want to use Rails and Bootstrap on a production environment I think use bootstrap-sass gem is a better option
Have you tried using rails-assets instead of the referenced method of adding Bootstrap 3? I use it on Heroku with success... and just add my own custom Bootstrap css in my normal assets folders which get loaded after the vanilla Bootstrap 3 and override it. Just add gem 'rails-assets-bootstrap' along with source 'https://rails-assets.org' to your gem file. May help diagnose if nothing else.
EIther of the two things you must take care to avoid assets compilation errors when you go live.
- Add all your assets(js/css) in manifest file(application.js/application.css)
- OR
- use assets.precompile=%w(custom.css custom.js) directive to handle them explicitly
because when u precompile...rails copies everyting(images/fonts) except js/css into public folder to be taken care by the server(apache),hence the setting # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false in production.rb during assets precompile fallback is disabled by default in production/staging as Rails assumes it will be handled by webserver.Hence we have manifest file to define our assets which gets precompiled during assets:precompile and verified by looking for public/assets/javascripts/application.css/js after compilation which gets created requiring all files mentioned in app/assets/stylesheets/application.css and app/assets/javascripts/application.js after running assets:precompile...so hope u know where you missed.
FOR MORE DETAILS..REFER this

Heroku asset compile not working with Rails 3.2 application

I feel like I have exhausted my resources trying to figure this out. I have yet to run into this error with a heroku/rails app before and am simply puzzled as to why my js/css isnt being compiled/uploaded to Heroku.
As stated in the heroku docs your options are to:
1. Compiling assets locally.
2. Compiling assets during slug compilation.
I tried the first option: ran RAILS_ENV=production bundle exec rake assets:precompile, added public/assets and saw the "Detected manifest.yml, assuming assets were compiled locally" line when deploying. No CSS.
I tried the second option (clean git checkout before assets:precompile). Added the 'config.assets.initialize_on_precompile = false' line as suggested for rails 3.x apps. And instead of seeing the expected:
Compiled jquery.js
Compiled jquery_ujs.js
Compiled application.js
Compiled application.css
etc etc
I get 'DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!' warnings. yet that folder is completely empty
Looked into this warning with no sign of it being the root cause for this. Feels like I'm going in circles so I am hoping someone has insight. Thanks in advance!
Heroku docs suggests that add 'rails_12factor' gem to gemfile. Precompling assets before pushing to heroku is not required. And you also must use Heroku's cedar stack only.

Rake assets are generated twice when precompiling them once from command line and once from within a Ruby script

When I do $ rake assets:precompile from the command line twice, then the assets are only generated once (as expected).
When I execute system 'rake assets:precompile' twice within a Ruby file, then the assets are also only generated once (as expected).
But when I execute it once from the command line and once from the Ruby file, then the assets are generated twice!
application-3e5c3563c16dfbc76bb833355133818d.js
application-3e5c3563c16dfbc76bb833355133818d.js.gz
application-61c5fbc18ff978365b43849b5787130e.css
application-61c5fbc18ff978365b43849b5787130e.css.gz
application-bb95b4b82324f57eb5d4ef0d20d5a68d.js
application-bb95b4b82324f57eb5d4ef0d20d5a68d.js.gz
application-c17c2cec3bacccb8ef58471e949679f2.css
application-c17c2cec3bacccb8ef58471e949679f2.css.gz
manifest-1627575ea003fb94ae02acecd73aecef.json
Why's that? And how can it be prevented? Thank you.
The reason why I'm doing this:
I'm searching for unused CSS selectors throughout my application. I forked the old DeadWeight gem and updated it so it's working with newer versions of Rails.
The problem is that I need the fully compiled application.css file when initializing DeadWeight, so I precompile it from within DeadWeight. And there I noticed that when there's already a precompiled version that was precompiled from the console (and not from within DeadWeight), it's not overwritten! So I have to manually remove it first (by doing another rake assets:clobber/clean) which isn't nice.

Rails 4, Heroku, Bootstrap - Overrides not working in Production

I've converted my Rails app to Rails 4. I'm using the Twitter Bootstrap Rails gem 2.2.6.
My application is working fine locally and in production. When I deploy everything looks fine. I'm not seeing any errors in my Heroku logs when browsing the site.
However, while my dev environment is displaying my color customizations properly, in production it's using the Bootstrap defaults.
I've tried recompiling my assets before each deployment using:
RAILS_ENV=production bundle exec rake assets:precompile
My application.css contains the usual:
*= require_self
*= require_tree .
My overrides are in bootstrap_and_overrides.css.less and look like this:
#navbarBackground: #4466af;
#navbarBackgroundHighlight: #4E7AC7;
#navbarText: #white;
#navbarLinkColor: #white;
#navbarLinkColorHover: #7FB2F0;
All of my other overrides are working correctly. It's just the navbar that's causing problems.
I've cleared my browser cache/history/etc. and that hasn't fixed it either.
Any ideas? I'm completely stumped.
I found the answer. When I checked my git repo I saw that there was a misspelling of a file which I had accidentally committed. I'd removed this from my file system, but it was still in my git repo. Removing this file, deleting all assets, recompiling and redeploying fixed it.

Resources