Class: ActiveRecordApi::Rest::Controller

Inherits:
IndexController
  • Object
show all
Defined in:
lib/active_record_api/rest/controller.rb

Instance Attribute Summary collapse

Attributes inherited from IndexController

#models

Instance Method Summary collapse

Methods inherited from IndexController

#index

Instance Attribute Details

#model ⇒ Object (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/active_record_api/rest/controller.rb', line 6

def model
  @model
end

Instance Method Details

#create ⇒ Object



18
19
20
21
22
23
24
# File 'lib/active_record_api/rest/controller.rb', line 18

def create
  if model.save
    redirect_to_model
  else
    render json: model.errors, status: :unprocessable_entity
  end
end

#destroy ⇒ Object



34
35
36
37
# File 'lib/active_record_api/rest/controller.rb', line 34

def destroy
  model.destroy!
  head :no_content
end

#show ⇒ Object



13
14
15
16
# File 'lib/active_record_api/rest/controller.rb', line 13

def show
  return unless stale?(last_modified: model.updated_at)
  render json: model, serializer: serializer
end

#update ⇒ Object



26
27
28
29
30
31
32
# File 'lib/active_record_api/rest/controller.rb', line 26

def update
  if model.update(filtered_params)
    redirect_to_model
  else
    render json: model.errors, status: :unprocessable_entity
  end
end