11require 'rails/railtie'
22require 'action_controller'
3- require 'action_controller/railtie'
43require 'active_support'
54
65require 'jsonapi/rails/parser'
@@ -12,35 +11,35 @@ class Railtie < ::Rails::Railtie
1211 MEDIA_TYPE = 'application/vnd.api+json' . freeze
1312 PARSER = JSONAPI ::Rails . parser
1413
15- initializer 'JSONAPI::Rails.initialize' do
16- Mime ::Type . register MEDIA_TYPE , :jsonapi
17- if ::Rails ::VERSION ::MAJOR >= 5
18- ActionDispatch ::Request . parameter_parsers [ :jsonapi ] = PARSER
19- else
20- ActionDispatch ::ParamsParser ::DEFAULT_PARSERS [ Mime [ :jsonapi ] ] = PARSER
21- end
14+ initializer 'jsonapi-rails.action_controller' do
15+ ActiveSupport . on_load ( :action_controller ) do
16+ require 'jsonapi/rails/action_controller'
17+ include ::JSONAPI ::Rails ::ActionController
2218
23- ActionController ::Renderers . add :jsonapi do |json , options |
24- unless json . is_a? ( String )
25- json = JSONAPI ::Rails ::Renderer . render ( json , options )
19+ Mime ::Type . register MEDIA_TYPE , :jsonapi
20+ if ::Rails ::VERSION ::MAJOR >= 5
21+ ::ActionDispatch ::Request . parameter_parsers [ :jsonapi ] = PARSER
22+ else
23+ ::ActionDispatch ::ParamsParser ::DEFAULT_PARSERS [ Mime [ :jsonapi ] ] = PARSER
24+ end
25+
26+ ::ActionController ::Renderers . add :jsonapi do |json , options |
27+ unless json . is_a? ( String )
28+ json = JSONAPI ::Rails ::Renderer . render ( json , options )
29+ end
30+ self . content_type ||= Mime [ :jsonapi ]
31+ self . response_body = json
2632 end
27- self . content_type ||= Mime [ :jsonapi ]
28- self . response_body = json
29- end
3033
31- ActionController ::Renderers . add :jsonapi_errors do |json , options |
32- unless json . is_a? ( String )
33- json = JSONAPI ::Rails ::ErrorRender . render_errors ( json , options )
34+ ::ActionController ::Renderers . add :jsonapi_errors do |json , options |
35+ unless json . is_a? ( String )
36+ json = JSONAPI ::Rails ::ErrorRender . render_errors ( json , options )
37+ end
38+ self . content_type ||= Mime [ :jsonapi ]
39+ self . response_body = json
3440 end
35- self . content_type ||= Mime [ :jsonapi ]
36- self . response_body = json
3741 end
3842 end
3943 end
4044 end
4145end
42-
43- ActiveSupport . on_load ( :action_controller ) do
44- require 'jsonapi/rails/action_controller'
45- include JSONAPI ::Rails ::ActionController
46- end
0 commit comments