Class: CrazyTrain::ResourcesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/crazy_train/resources_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#jwt_payload, #jwt_token, #setup_role, #switch_role, #teardown_role, #verify_token

Instance Method Details

#createObject



16
17
18
19
20
# File 'app/controllers/crazy_train/resources_controller.rb', line 16

def create
  klass.create!(resource_params.to_h)

  head :created
end

#destroyObject



29
30
31
32
33
34
# File 'app/controllers/crazy_train/resources_controller.rb', line 29

def destroy
  resource = klass.find(params[:id])
  resource.destroy!

  head :no_content
end

#indexObject



3
4
5
6
7
8
9
# File 'app/controllers/crazy_train/resources_controller.rb', line 3

def index
  query_builder = CrazyTrain::QueryBuilder.new(klass, params)
  query_builder.parse!

  records = query_builder.query
  render json: records
end

#showObject



11
12
13
14
# File 'app/controllers/crazy_train/resources_controller.rb', line 11

def show
  resource = klass.find(params[:id])
  render json: resource
end

#updateObject



22
23
24
25
26
27
# File 'app/controllers/crazy_train/resources_controller.rb', line 22

def update
  resource = klass.find(params[:id])
  resource.update!(resource_params.to_h)

  head :no_content
end