Class: Shutl::Rails::BackendResourcesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Auth::AuthenticatedRequest
Defined in:
app/controllers/shutl/rails/backend_resources_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



47
48
49
50
51
52
53
# File 'app/controllers/shutl/rails/backend_resources_controller.rb', line 47

def create
  authenticated_request do
    self.instance_variable= resource_klass.create id_params.merge(attributes_from_params), auth: access_token
  end

  render status: instance_variable.status, json: instance_variable.parsed
end

#destroyObject



67
68
69
70
71
72
73
# File 'app/controllers/shutl/rails/backend_resources_controller.rb', line 67

def destroy
  authenticated_request do
    resource_klass.destroy(id_params.merge(id: params[:id]), auth: access_token)
  end

  render nothing: true, status: 204
end

#indexObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/shutl/rails/backend_resources_controller.rb', line 28

def index
  authenticated_request do
    instance_variable_set(
      pluralized_instance_variable_name,
      resource_klass.all(id_params.merge auth: access_token))
  end

  response_collection = pluralized_instance_variable.map do |o|
    attributes_to_front_end o.attributes
  end

  render json: response_collection
end

#newObject



42
43
44
45
# File 'app/controllers/shutl/rails/backend_resources_controller.rb', line 42

def new
  self.instance_variable= resource_klass.new
  respond_with_json
end

#showObject



55
56
57
# File 'app/controllers/shutl/rails/backend_resources_controller.rb', line 55

def show
  respond_with_json
end

#updateObject



59
60
61
62
63
64
65
# File 'app/controllers/shutl/rails/backend_resources_controller.rb', line 59

def update
  authenticated_request do
    resource_klass.update id_params.merge(attributes_from_params), auth: access_token
  end

  render nothing: true, status: 204
end