1
1
require 'rails/railtie'
2
2
require 'action_controller'
3
- require 'action_controller/railtie'
4
3
require 'active_support'
5
4
6
5
require 'jsonapi/rails/parser'
@@ -12,35 +11,35 @@ class Railtie < ::Rails::Railtie
12
11
MEDIA_TYPE = 'application/vnd.api+json' . freeze
13
12
PARSER = JSONAPI ::Rails . parser
14
13
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
22
18
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
26
32
end
27
- self . content_type ||= Mime [ :jsonapi ]
28
- self . response_body = json
29
- end
30
33
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
34
40
end
35
- self . content_type ||= Mime [ :jsonapi ]
36
- self . response_body = json
37
41
end
38
42
end
39
43
end
40
44
end
41
45
end
42
-
43
- ActiveSupport . on_load ( :action_controller ) do
44
- require 'jsonapi/rails/action_controller'
45
- include JSONAPI ::Rails ::ActionController
46
- end
0 commit comments