Browse files

Fix for asset loading issue:

When assets have been copied with rake admin:copy_assets, then rails_admin should NOT insert
another ActionDispatch::Static middleware, because it eclipses Rails's native middleware and assets
are loaded from rails_admin's public folder instead of the application's public folder.
Fixed by checking if any of the rails_admin subdirectories exist in any of the static asset classes
(images, javascripts, stylesheets).
Also, if the middleware is inserted, it should be done AFTER, not IN FRONT of Rails's own static asset
middleware, to permit precedence to the application's public folder over the gem's.
  • Loading branch information...
1 parent d07a2e4 commit 1cd52f385a8c03a82fb7f4e6dfa95f9d23b05e3c @papercheck committed Mar 10, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/rails_admin/engine.rb
8 lib/rails_admin/engine.rb
@@ -4,8 +4,12 @@
module RailsAdmin
class Engine < Rails::Engine
initializer "static assets" do |app|
- if app.config.serve_static_assets
- app.middleware.insert 0, ::ActionDispatch::Static, "#{root}/public"
+ # If assets were copied for app's public/ folder, e.g. via rake admin:copy_assets, then don't insert the static
+ # asset server, as it iterferes with Rails's own asset server.
+ if app.config.serve_static_assets &&
+ !(%w(stylesheets images javascripts).any?{|cat| File.exists?(File.join(Rails.root,'public',cat,'rails_admin'))})
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"

0 comments on commit 1cd52f3

Please sign in to comment.