Class: PgInsights::QueriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pg_insights/queries_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /pg_insights/queries



10
11
12
13
14
15
16
17
# File 'app/controllers/pg_insights/queries_controller.rb', line 10

def create
  @query = PgInsights::Query.new(query_params)
  if @query.save
    render json: { success: true, query: @query.as_json(only: [ :id, :name, :sql, :description, :category ]) }, status: :created
  else
    render json: { success: false, errors: @query.errors.full_messages }, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /pg_insights/queries/:id



29
30
31
32
# File 'app/controllers/pg_insights/queries_controller.rb', line 29

def destroy
  @query.destroy
  head :no_content
end

#updateObject

PATCH/PUT /pg_insights/queries/:id



20
21
22
23
24
25
26
# File 'app/controllers/pg_insights/queries_controller.rb', line 20

def update
  if @query.update(query_params)
    render json: { success: true, query: @query.as_json(only: [ :id, :name, :sql, :description, :category ]) }
  else
    render json: { success: false, errors: @query.errors.full_messages }, status: :unprocessable_entity
  end
end