Class: CompletionKit::Api::V1::DatasetsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/completion_kit/api/v1/datasets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
# File 'app/controllers/completion_kit/api/v1/datasets_controller.rb', line 17

def create
  dataset = Dataset.new(dataset_params)
  if dataset.save
    render json: dataset, status: :created
  else
    render json: {errors: dataset.errors}, status: :unprocessable_entity
  end
end

#destroyObject



34
35
36
37
# File 'app/controllers/completion_kit/api/v1/datasets_controller.rb', line 34

def destroy
  @dataset.destroy!
  head :no_content
end

#indexObject



7
8
9
10
11
# File 'app/controllers/completion_kit/api/v1/datasets_controller.rb', line 7

def index
  scope = Dataset.includes(:tags)
  scope = filter_by_tags(scope)
  render json: paginate(scope.order(created_at: :desc))
end

#showObject



13
14
15
# File 'app/controllers/completion_kit/api/v1/datasets_controller.rb', line 13

def show
  render json: @dataset
end

#updateObject



26
27
28
29
30
31
32
# File 'app/controllers/completion_kit/api/v1/datasets_controller.rb', line 26

def update
  if @dataset.update(dataset_params)
    render json: @dataset
  else
    render json: {errors: @dataset.errors}, status: :unprocessable_entity
  end
end