Class: ActiveRecordApi::Rest::Controller

Inherits:
ApplicationController
  • Object
show all
Includes:
GracefulErrors
Defined in:
lib/active_record_api/rest/controller.rb

Direct Known Subclasses

Auth::Controller

Instance Method Summary collapse

Instance Method Details

#createObject



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

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

#destroyObject



36
37
38
39
# File 'lib/active_record_api/rest/controller.rb', line 36

def destroy
  model.destroy!
  head :no_content
end

#indexObject



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

def index
  response.headers['x-total'] = models_count
  response.headers['x-link-next'] = next_url unless next_url.nil?
  render json: models_remaining.limit(limit), each_serializer: serializer
end

#showObject



16
17
18
# File 'lib/active_record_api/rest/controller.rb', line 16

def show
  render json: model, serializer: serializer
end

#updateObject



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

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