Module: Shamu::JsonApi::Rails::Responder

Included in:
ApiResponder
Defined in:
lib/shamu/json_api/rails/responder.rb

Overview

Support JSON API responses with the standard rails #respond_with method.

Instance Method Summary collapse

Instance Method Details

#to_jsonString Also known as: to_json_api

Render the response as JSON

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/shamu/json_api/rails/responder.rb', line 10

def to_json
  if has_errors?
    display_errors
  elsif get?
    display resource
  elsif put? || patch?
    display resource, :location => api_location
  elsif post?
    display resource, :status => :created, :location => api_location
  else
    head :no_content
  end
end