Module: Terrain::Resource::Actions

Defined in:
lib/terrain/resource.rb

Instance Method Summary collapse

Instance Method Details

#createObject



33
34
35
36
37
38
# File 'lib/terrain/resource.rb', line 33

def create
  record = resource.new(permitted_params)
  authorize_record(record)

  render json: create_record, include: [], status: 201
end

#destroyObject



54
55
56
57
58
59
60
# File 'lib/terrain/resource.rb', line 54

def destroy
  record = load_record
  authorize_record(record)
  destroy_record(record)

  render nothing: true, status: 204
end

#indexObject



23
24
25
26
27
28
29
30
31
# File 'lib/terrain/resource.rb', line 23

def index
  scope = order(resource_scope)

  range = request.headers['Range']
  page = Terrain::Page.new(scope, range)

  headers['Content-Range'] = page.content_range
  render json: page.records, include: (params[:include] || [])
end

#showObject



40
41
42
43
44
45
# File 'lib/terrain/resource.rb', line 40

def show
  record = load_record
  authorize_record(record)

  render json: record, include: params[:include] || []
end

#updateObject



47
48
49
50
51
52
# File 'lib/terrain/resource.rb', line 47

def update
  record = load_record
  authorize_record(record)

  render json: update_record(record), include: []
end