Module: RenderApiHelper
- Defined in:
- app/helpers/render_api_helper.rb
Instance Method Summary collapse
- #embed_stack_in_json_response? ⇒ Boolean
-
#render_json_response(proc_code) ⇒ Object
This method will accept a proc, execute it and render the json.
Instance Method Details
#embed_stack_in_json_response? ⇒ Boolean
2 3 4 5 |
# File 'app/helpers/render_api_helper.rb', line 2 def return true if Rails.env.development? Rails.env.production? && ["true", "t", "1", "yes"].include?(params[:debug].to_s.downcase.strip) end |
#render_json_response(proc_code) ⇒ Object
This method will accept a proc, execute it and render the json
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/render_api_helper.rb', line 8 def render_json_response(proc_code) begin proc_code.call @success = @success == false ? (false) : (true) rescue Exception => e @success = false @errors = { heading: I18n.translate("api.general.unexpected_failure.heading"), message: I18n.translate("api.general.unexpected_failure.message"), details: e., stacktrace: ( ? e.backtrace : nil) } end @status ||= 200 response_hash = {success: @success} response_hash[:alert] = @alert unless @alert.blank? response_hash[:data] = @data unless @data.blank? response_hash[:errors] = @errors unless @errors.blank? response_hash[:total_data] = @total_data unless @total_data.blank? response_hash[:per_page] = @per_page unless @per_page.blank? response_hash[:current_page] = @current_page unless @current_page.blank? render status: @status, json: response_hash return end |