Reputation: 40780
Wanted to try something new, using the awesome twitter bootstrap and their Less CSS. I finally got my app up and running, but it crashed at heroku's read-only system. I'm trying to figure out my options, using LESS, rails 3.2 and heroku. This is what I think can do:
(1) One option is: precompile.
bundle exec rake assets:precompile
git commit public/assets -m "tedious precompilation task"
git push heroku
I'll surely forget to precompile once, just push the changes to heroku and piss off my users. Not what I want.
(2) A good option is less.js
. It compiles client-side. Is this what most use?
(3) A better option, IMO. Precompile to cache. Neither a precompile routine nor extra client side work. What I'm asking, is there something like hassle for SASS, for less?
UPDATE 26th jan-12: people don't use hassle rails 3.1+, they use sass-rails (default rails 3.2) with the asset pipeline. hassle is sooo rails 3.0 ;) The rake precompile step failed at heroku. /UPDATE
I find the idea of compiling to static rack cache to be served by varnish absolutely brilliant. I'd prefer it over having every client needing to compile my less css themselves when it can be done one time, at deploy.
UPDATE 25th jan: Updating myself on heroku. The cedar stack supports the asset pipeline, so there is no need for the hassle gem anymore. Correct? /UPDATE
What to do?
Upvotes: 2
Views: 4679
Reputation: 40780
Solution:
application.rb
config.assets.initialize_on_precompile = false
Simple solution, once you know it .... !
Use with gem less-rails
Now all assets are compiled and will be cached, (as in option 3). The asset pipeline is awesome!
Problem background:
Heroku couldn't precompile as rails pr default tries to initialize and attach to DB, but the ENV vars ain't available yet. Without it you'd get
$ git push heroku
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Just as a note: Heroku has a way of providing the environment variables at precompile stage too.
$ heroku plugins:install http://github.com/heroku/heroku-labs.git
$ heroku labs:enable user_env_compile [--app my_app]
Upvotes: 6
Reputation: 23566
You have gem:
gem 'less-rails'
If you add it to your Gemfile
then you can use your .less
files the same way as .scss
and .sass
.
EDIT But if you want use Bootstrap then it is even easier:
gem 'twitter-bootstrap-rails'
And then
rails g bootstrap:install
More info at GitHub repo
Upvotes: 0