Module: JsonOutputHelper
- Included in:
- ActionController::Base
- Defined in:
- lib/json_output_helper.rb
Instance Method Summary collapse
-
#json_response(type, hash = {}) ⇒ Object
JSON helpers —————————————————————————————————- a nice standard response schema for json.
-
#render_json_response(type, hash = {}) ⇒ Object
render our standardized json response.
Instance Method Details
#json_response(type, hash = {}) ⇒ Object
JSON helpers
a nice standard response schema for json
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/json_output_helper.rb', line 6 def json_response(type, hash = {}) # we require one of these types unless [ :ok, :redirect, :error ].include?(type) raise "Invalid json response type: #{type}" end # To keep the structure consistent, we'll build the json # structure with these default properties. default_json = { :status => type, :html => nil, :notice => nil, :to => nil }.merge(hash) return default_json end |
#render_json_response(type, hash = {}) ⇒ Object
render our standardized json response
24 25 26 |
# File 'lib/json_output_helper.rb', line 24 def render_json_response(type, hash = {}) render :json => json_response(type, hash) end |