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
rails beginner here
I am trying to set an app to production but having big issues with the asset pipeline. Under development every asset is generated under /assets/blabla.extension
However, I am running nginx and when running rake assets:precompile it creates assets under /public/assets as it should. But when I visit my app it generates urls like /application.css and not /assets/application-digestq12343.css as it should.
I think there is an easy fix to this problem.. but I cannot find it. Please help me!
Update:
From the documentation I read that Sprockets "default" is /assets but it certainly isn't in my application. I use the latest version of rails. Can the documentation be outdated?
http://edgeguides.rubyonrails.org/asset_pipeline.html
Even if I add config.assets.prefix = "/assets" to my production it would still mean that I would not load the assets since the digest would be missing.
I believe this is the same problem I was experiencing. Instead of using url()in your css (or scss), use asset-data-url() and add config.assets.enabled = true to your application config file. Then, rake assets:precompile before you push.
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.
I have a rails application with locomotive cms engine mounted.
Compilation of all locomotive assets takes a lot of time (5-10 minutes). Since I do not change locomotive assets, I would like to precompile it only once.
The best solution would be to force rake assets:precompile to compile only application assets and skip compilation of locomotive assets. Already compiled locomotive assets might be added to the git repository.
Is there any easy way to achieve this?
Try Turbo Sprockets. From the README:
Speeds up your Rails 3 rake assets:precompile by only recompiling
changed assets, based on a hash of their source files
Only compiles once to generate both fingerprinted and non-fingerprinted assets
Lately I have to precompile my assets to see my css changes in my development environment. I don't know why this, the environment setting config.assets.debug is still set to true. I find this rather annoying, I believe I didn't have to run precompile after every change before. How do I make rails compile on page load again?
I'm running Rails 3.1.3. I don't know what other info to provide, please let me know what you need to know to solve this.
Try completely removing your compiled assets and it should reset to the default development behavior. Otherwise, Rails will keep trying to load your precompiled public/assets/ files before loading the stuff under app/assets/:
rake assets:clean