Class: ActiveResponse::Responders::JSON
- Inherits:
-
HTML
- Object
- Base
- HTML
- ActiveResponse::Responders::JSON
show all
- Defined in:
- lib/active_response/responders/json.rb
Instance Attribute Summary
Attributes inherited from Base
#controller, #format
Instance Method Summary
collapse
Methods inherited from HTML
#redirect
Methods inherited from Base
available_formats, #initialize, respond_to, type, #type
Instance Method Details
#collection(**opts) ⇒ Object
8
9
10
11
|
# File 'lib/active_response/responders/json.rb', line 8
def collection(**opts)
opts[:json] = opts.delete(:collection)
controller.render opts
end
|
#destroyed(_opts) ⇒ Object
13
14
15
|
# File 'lib/active_response/responders/json.rb', line 13
def destroyed(_opts)
controller.head :no_content, content_type: content_type
end
|
17
18
19
|
# File 'lib/active_response/responders/json.rb', line 17
def form(**_opts)
raise NotImplementedError, 'Forms are not available in JSON'
end
|
#invalid_resource(**opts) ⇒ Object
21
22
23
24
25
|
# File 'lib/active_response/responders/json.rb', line 21
def invalid_resource(**opts)
opts[:json] = opts.delete(:resource).errors
opts[:status] ||= :unprocessable_entity
controller.render opts
end
|
#new_resource(**opts) ⇒ Object
27
28
29
30
|
# File 'lib/active_response/responders/json.rb', line 27
def new_resource(**opts)
opts[:status] = :created
controller.respond_with_resource(opts)
end
|
#resource(**opts) ⇒ Object
32
33
34
35
|
# File 'lib/active_response/responders/json.rb', line 32
def resource(**opts)
opts[:json] = opts.delete(:resource)
controller.render opts
end
|
#updated_resource(**opts) ⇒ Object
37
38
39
|
# File 'lib/active_response/responders/json.rb', line 37
def updated_resource(**opts)
controller.respond_with_resource(opts)
end
|