17

I'm using Twitter's Bootstrap translated to SCSS files. It works in local-development, but when I precompile and push to Heroku (using Cedar stack), I get this:

> Started GET "/" for 74.57.16.130 at 2012-01-28 17:16:36 +0000 
> Processing by StaticPagesController#home as HTML  Rendered
> static_pages/home.html.erb within layouts/application (0.7ms) 
> Completed 500 Internal Server Error in 4ms
> 
>  ActionView::Template::Error (couldn't find file 'twitter/bootstrap'  
> (in /app/app/assets/stylesheets/application.scss.css:11)):
>      8: </head>
>      6:   <%= javascript_include_tag "application" %>
>      4:   <title><%= full_title(yield(:title)) %></title>
>      2: <html>
>      5:   <%= stylesheet_link_tag    "application", :media => "all" %>        
app/views/layouts/application.html.erb:5:in
> `_app_views_layouts_application_html_erb___288948710373692320_32137840'
>      3: <head>    cache: [GET /] miss
> 
>      7:   <%= csrf_meta_tags %>  cache: [GET /favicon.ico] miss

I'm using Rails 3.2.0, the app was working on Heroku until I added the SASS files.

Jonathan Soifer
  • 2,715
  • 6
  • 27
  • 50
johncho
  • 641
  • 2
  • 11
  • 25

6 Answers6

27

Are you using a gem? Make sure your gem is not part of the assets group and is accessible in production.

From GemFile

# Gems used only for assets and not in production environments by default.

So just move the gem outside of any group and you should be okay.

Community
  • 1
  • 1
mike
  • 1,526
  • 3
  • 17
  • 25
  • From what I had understood, I thought when I ran the precompile command, that it would compile all of the SASS files into one CSS file. Is this not the case? (I'm so new at this, but loving it) – johncho Feb 06 '12 at 19:42
  • 1
    I don't think the SASS from the gem you are using gets precompiled, I'm not sure anyway. – mike Feb 08 '12 at 19:27
  • I think you've found the answer. Thank you very much. – johncho Feb 09 '12 at 15:02
  • @mike you're god! If only i could upvote this 1000 times. _/\_ – shivam Jun 26 '15 at 19:50
4

Just put this in your gemfile

gem "twitter-bootstrap-rails", "~> 2.0rc0"

There's invalid CSS in BootStrap 2.0 which causes SCSS compilation to fail

You can verify this by looking at the output of

git push heroku master 

You should see some error like:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       Invalid CSS after "...er-radius:0 \0/": expected expression (e.g. 1px, bold), was ";}"
       (in /tmp/build_1k8ugei34dpcw/app/assets/stylesheets/application.css)

       Tasks: TOP => assets:precompile:primary
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
Doug
  • 14,387
  • 17
  • 74
  • 104
3

In config/environments/production.rb add this line:

config.assets.precompile = [/^[-_a-zA-Z0-9]*\..*/]

My guess is it is not adding all your assets.

Mitch Dempsey
  • 38,725
  • 6
  • 68
  • 74
  • I'mma try this when I get home. Thank you. Is this considered regular(best) practice? – johncho Jan 30 '12 at 14:25
  • @JohnCho I have no idea. I just know that when I added more javascript files, my compiler in production was completely ignoring them, and I had to add this line. – Mitch Dempsey Jan 30 '12 at 20:47
  • I tried it this morning, modified the files, ran precompile, then push to heroku which all went fine, but I still have the same errors in the log. =( – johncho Jan 31 '12 at 11:47
  • @JohnCho what is `twitter/bootstrap` ? is that a file? Is it a folder? – Mitch Dempsey Jan 31 '12 at 19:03
  • It's a SCSS file that imports all of the other SCSS files in order (and it works as it should in development). I'm gonna try import via wildcard tonight, and see if it works in Production, then I'll know if it has to do with how things are imported. I'm grasping at straws a bit here. – johncho Jan 31 '12 at 20:23
  • This only works if you have a javascript compiler in production. "rake assets:precompile" and then pushing that is the preferred way. – Cory Foy May 23 '12 at 11:51
  • i solved it by replacing the following line `config.assets.compile = false` with `config.assets.compile = true` – Saad Masood Sep 10 '13 at 01:03
2

this solved the issue in heroku at least

just downgrade to sass-rails 3.1.4

group :assets do
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'sass-rails', '3.1.4'
  gem 'bootstrap-sass', '~> 2.0.2'
end
Justin D.
  • 4,946
  • 5
  • 36
  • 69
Siddhartha Mukherjee
  • 6,138
  • 3
  • 23
  • 11
0

When you see something like this when you are deploying rails app to heroku.com

Precompiling assets failed, enabling runtime asset compilation
...
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port xxxx?

Just add this to config/application.rb

config.assets.initialize_on_precompile = false
Lewy
  • 729
  • 7
  • 18
0

Make sure, in config/environments/production.rb, you have...

config.serve_static_assets = true
brntsllvn
  • 931
  • 11
  • 18