Search code examples
cssruby-on-railsproduction-environment

Rails assets are in a sub directory and cannot load in production


Currently my event CSS is in app/assets/stylesheets/pages/events.scss and in development mode it looks fine and the assets are loaded. But on production, it looks like these pages are not loaded at all. I'm not sure how to fix this problem. I've looked at Rails 4: assets not loading in production but I am not familiar with the config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb) since it seems like the path itself is not working in production.

app/assets/stylesheets/application.scss:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *


 *#= require bootstrap-wysihtml5
 *#= require rails_bootstrap_forms
 *#= require jquery.jcrop
 *= require custom
 *= require_self 
*/

@import "bootstrap-sprockets";
@import "bootstrap";
@import "scaffolds";

app/views/events/index.html.erb:

<% content_for :head do %>
  <%= stylesheet_link_tag "pages/events", :media => "all" %>
<% end %>

app/assets/stylesheets/pages/events.scss

@import "globals/helpers";
@import "vendors/animate";

.events-bar {
/*  a[class*="btn"] {
  height: 36px;
  display: inline-block;
}*/
#toggleBar {
  margin-top: 14px;
}
.btn-dashboard { 
   background-color: #fdf9ff;
   color: $eventsColour !important;  
   &:hover {
     background-color: $eventsColour-dark !important;
   }
 }
}

It's been hard to debug since it works fine in development and not in production. It looks like that all of the files in subdirectory (app/assets/stylesheet/pages/*.scss) are not working in production. Any insight will help, thanks.


Solution

  • You just need to add events to your precompile assets list since its not compiled with application.scss the format you want is

    config.assets.precompile += %w( pages/events.scss )

    then

    bundle exec rake assets:precompile