Skip to content

Commit

Permalink
Fix for asset loading issue:
Browse files Browse the repository at this point in the history
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
papercheck committed Mar 10, 2011
1 parent d07a2e4 commit 1cd52f3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rails_admin/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
end
end

Expand Down

0 comments on commit 1cd52f3

Please sign in to comment.