Module: RenderJsonRails::Helper
- Defined in:
- lib/render_json_rails/helper.rb
Instance Method Summary collapse
-
#render_json(object, override_render_json_config: nil, additional_config: nil, status: nil, location: nil) ⇒ Object
xxx.yyyy.test/object.json?formatted=yes&fields[invoice]=number,sales_code&fields[invoice_position]=price_gross&include=positions parametry: formatted=yes& fields=number,sales_code fields=price_gross include=positions.
Instance Method Details
#render_json(object, override_render_json_config: nil, additional_config: nil, status: nil, location: nil) ⇒ Object
xxx.yyyy.test/object.json?formatted=yes&fields[invoice]=number,sales_code&fields[invoice_position]=price_gross&include=positions parametry: formatted=yes& fields=number,sales_code fields=price_gross include=positions
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/render_json_rails/helper.rb', line 20 def render_json(object, override_render_json_config: nil, additional_config: nil, status: nil, location: nil) raise "objekt nie moze byc null" if object == nil if object.class.to_s.include?('ActiveRecord_Relation') return render json: [] if !object[0] class_object = object[0].class else class_object = object.class end includes = params[:include].to_s.split(',').map { |el| el.to_s.strip } if params[:include] = class_object.( includes: includes, fields: params[:fields], override_render_json_config: override_render_json_config, additional_config: additional_config ) if params[:formatted] && !Rails.env.development? || params[:formatted] != 'no' && Rails.env.development? json = JSON.pretty_generate(object.as_json()) render json: json, status: status, location: location else [:json] = object [:status] = status [:location] = location render end end |