0

I have an admin section of my site that uses an 'admin' layout.

class Admin::BaseController < ActionController::Base
  layout "admin"

in layouts/admin.html.slim

 = stylesheet_link_tag "admin", :media => "all"
 = javascript_include_tag "admin"

I get an error for the admin.js and admin.css

Started GET "/stylesheets/admin.css" for x.x.x.x at 2013-10-25 13:18:16 +0000
F, [2013-10-25T13:18:16.505425 #31550] FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/stylesheets/admin.css"):

this works perfectly in development and the frontend assets are loading normally in production, what can the problem be?

raphael_turtle
  • 7,154
  • 10
  • 55
  • 89
  • possible duplicate of [Rails 4 assets.precompile](http://stackoverflow.com/questions/14882337/rails-4-assets-precompile) – pdu Oct 25 '13 at 13:26
  • adding 'config.assets.precompile += %w( admin.js admin.css )' to application.rb fixes the problem, though I don't know why it happens.. – raphael_turtle Oct 25 '13 at 14:11
  • Added an explanation for you. – pdu Oct 28 '13 at 08:06

1 Answers1

2

The reason is that your rails server (webrick, thin, ...) serves your assets uncompiled, where it looks for it in several places (like app/assets or vendor/assets). In production, rails assumes that the production webserver handles asset serving, which are served from public/.

Since compilation on runtime – or delivering them uncompiled at all – slows down page serving, they are compiled into the name of its known manifest-files that reference your styles (that is application.{css/js} by default), which you do by invoking rake assets:precompile.

Add config.assets.precompile += %w( admin.css ) to config/application.rb or config/environments/production.rb to add your admin.css manifest so rails know that it also has to compile that one. Then run rake assets:precompile (if you've put it into the later, you may need to add RAILS_ENV=production).

pdu
  • 10,295
  • 4
  • 58
  • 95