Class: ActiveRecordApi::Rest::Controller

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

Instance Method Summary collapse

Methods inherited from IndexController

#index

Instance Method Details

#create ⇒ Object



14
15
16
17
18
19
20
# File 'lib/active_record_api/rest/controller.rb', line 14

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

#destroy ⇒ Object



30
31
32
33
# File 'lib/active_record_api/rest/controller.rb', line 30

def destroy
  model.destroy!
  head :no_content
end

#show ⇒ Object



9
10
11
12
# File 'lib/active_record_api/rest/controller.rb', line 9

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

#update ⇒ Object



22
23
24
25
26
27
28
# File 'lib/active_record_api/rest/controller.rb', line 22

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