Class: ForestLiana::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/forest_liana/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_user_from_jwtObject



29
30
31
32
33
34
35
36
# File 'app/controllers/forest_liana/application_controller.rb', line 29

def authenticate_user_from_jwt
  if request.headers['Authorization']
    JWT.decode request.headers['Authorization'].split[1],
      ForestLiana.jwt_signing_key
  else
    render nothing: true, status: 401
  end
end

#serialize_model(model, options = {}) ⇒ Object



7
8
9
10
# File 'app/controllers/forest_liana/application_controller.rb', line 7

def serialize_model(model, options = {})
  options[:is_collection] = false
  JSONAPI::Serializer.serialize(model, options)
end

#serialize_models(models, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/forest_liana/application_controller.rb', line 12

def serialize_models(models, options = {})
  options[:is_collection] = true
  json = JSONAPI::Serializer.serialize(models, options)

  if options[:count]
    json[:meta] = {} unless json[:meta]
    json[:meta][:count] = options[:count]
  end

  if !options[:has_more].nil?
    json[:meta] = {} unless json[:meta]
    json[:meta][:has_more] = options[:has_more]
  end

  json
end