File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,11 +24,6 @@ class Engine < Rails::Engine
2424 end
2525
2626 initializer 'RailsAdmin setup middlewares' do |app |
27- app . config . session_store :cookie_store
28- app . config . middleware . use ActionDispatch ::Cookies
29- app . config . middleware . use ActionDispatch ::Flash
30- app . config . middleware . use ActionDispatch ::Session ::CookieStore , app . config . session_options
31- app . config . middleware . use Rack ::MethodOverride
3227 app . config . middleware . use Rack ::Pjax
3328 end
3429
@@ -47,5 +42,24 @@ class Engine < Rails::Engine
4742 rake_tasks do
4843 Dir [ File . join ( File . dirname ( __FILE__ ) , '../tasks/*.rake' ) ] . each { |f | load f }
4944 end
45+
46+ initializer 'RailsAdmin check for required middlewares' , after : :build_middleware_stack do |app |
47+ has_session_store = app . config . middleware . to_a . any? { |m | m . klass . try ( :<= , ActionDispatch ::Session ::AbstractStore ) } || ::Rails . version < '5.0'
48+ loaded = app . config . middleware . to_a . map ( &:name )
49+ required = %w( ActionDispatch::Cookies ActionDispatch::Flash Rack::MethodOverride )
50+ missing = required - loaded
51+ unless missing . empty? && has_session_store
52+ configs = missing . map { |m | "config.middleware.use #{ m } " }
53+ configs << "config.middleware.use #{ app . config . session_store . try ( :name ) || 'ActionDispatch::Session::CookieStore' } , #{ app . config . session_options } " unless has_session_store
54+ raise <<-EOM
55+ Required middlewares for RailsAdmin are not added
56+ To fix tihs, add
57+
58+ #{ configs . join ( "\n " ) }
59+
60+ to config/application.rb.
61+ EOM
62+ end
63+ end
5064 end
5165end
You can’t perform that action at this time.
0 commit comments