@@ -16,23 +16,27 @@ class Railtie < ::Rails::Railtie
1616 jsonapi_error : ErrorsRenderer . new
1717 } . freeze
1818
19- initializer 'jsonapi-rails.action_controller' do
20- ActiveSupport . on_load ( :action_controller ) do
21- include ::JSONAPI ::Rails ::Controller
19+ initializer 'jsonapi.init' , after : :load_config_initializers do
20+ if JSONAPI ::Rails . config . register_mime_type
21+ Mime ::Type . register MEDIA_TYPE , :jsonapi
22+ end
2223
23- if JSONAPI ::Rails . config . register_mime_type
24- Mime ::Type . register MEDIA_TYPE , :jsonapi
24+ if JSONAPI ::Rails . config . register_parameter_parser
25+ if ::Rails ::VERSION ::MAJOR >= 5
26+ ::ActionDispatch ::Request . parameter_parsers [ :jsonapi ] = PARSER
27+ else
28+ ::ActionDispatch ::ParamsParser ::DEFAULT_PARSERS [ Mime [ :jsonapi ] ] = PARSER
2529 end
30+ end
2631
27- if JSONAPI ::Rails . config . register_parameter_parser
28- if ::Rails ::VERSION ::MAJOR >= 5
29- ::ActionDispatch ::Request . parameter_parsers [ :jsonapi ] = PARSER
30- else
31- ::ActionDispatch ::ParamsParser ::DEFAULT_PARSERS [ Mime [ :jsonapi ] ] = PARSER
32- end
32+ if JSONAPI ::Rails . config . extend_action_controller
33+ ActiveSupport . on_load ( :action_controller ) do
34+ include ::JSONAPI ::Rails ::Controller
3335 end
36+ end
3437
35- if JSONAPI ::Rails . config . register_renderers
38+ if JSONAPI ::Rails . config . register_renderers
39+ ActiveSupport . on_load ( :action_controller ) do
3640 RENDERERS . each do |name , renderer |
3741 ::ActionController ::Renderers . add ( name ) do |resources , options |
3842 # Renderer proc is evaluated in the controller context.
0 commit comments