fullybaked
fullybaked

Reputation: 4127

Rails Assets not compiling correctly

I've been banging my head on this problem for a few days so hoping someone here can help.

I've got a very basic Rails app (3.2.13) using the following gems for twitter bootstrap styling

gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'

The assets are laid out in the following manner

- stylesheets
    - all
        bootstrap_override.css.scss
    - public
        styles.css.scss
    - admin
        styles.css.scss

bootstrap override has the following code in it

$baseLineHeight: 18px;
$baseFontSize: 14px;
$sansFontFamily: 'Open Sans';
$baseFontFamily: 'Open Sans';
$monoFontFamily: 'Ubuntu Mono';
$linkColor: #56b1e4;
$btnPrimaryBackground: #86b063;

@import "bootstrap";
@import 'font-awesome';

public.css.scss has the following and is used in the default layout on all public pages

/*
 *
 *= require_self
 *= require_tree ./all
 *= require_tree ./public
 */

admin.css.scss is the following and used on pages withint the admin namespace

/*
 *
 *= require_self
 *= require_tree ./all
 *= require_tree ./admin
 */

Heres the issue:

On production, public pages work fine with no errors. But admin pages throw a 500 with the following

ActionView::Template::Error (File to import not found or unreadable: bootstrap.
Load path: /sites/blog/releases/20130613100153
  (in /sites/blog/releases/20130613100153/app/assets/stylesheets/all/bootstrap_and_override.css.scss)):
    5:     meta charset="utf-8"
    6:
    7:     = render 'layouts/custom_fonts'
    8:     = stylesheet_link_tag "admin", media: 'all', 'data-turbolinks-track' => true
    9:     = javascript_include_tag "application", 'data-turbolinks-track' => true
    10:     = render 'layouts/custom_fonts'
    11:
  app/assets/stylesheets/all/bootstrap_and_override.css.scss:14
  app/views/layouts/login.html.slim:8:in `_app_views_layouts_login_html_slim___3383884768077581761_25787440'

I've tried clearing the cache, re-deploying (done via Capistrano with the asset pipeline plugin), statically compiling assets and nothing works.

I'm obviously missing something critical from the assets setup, but what?

Oh and in development env it all works perfectly, I assume due to the asset pipleline compiling assets on the fly.

Upvotes: 0

Views: 725

Answers (1)

davidfurber
davidfurber

Reputation: 5518

The problem may be that the asset pipeline has already compiled bootstrap into public and doesn't want to add it also to admin. Two possible approaches:

  1. Separate the bootstrap file from the public and admin files, so that the client has to load a base CSS file that includes bootstrap, plus the public or admin specific files.

  2. Include public and admin in one application.css file. If you need to distinguish the admin from the public css, use something like a body class for namespacing.

Upvotes: 1

Related Questions