Newer
Older
Douglas A. C
committed
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class V1::QuestionsController < ApplicationController
before_action :set_question, only: [:show, :update, :destroy]
before_action :authorize!, only: [:create, :update, :destroy]
Douglas A. C
committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# GET /questions
def index
@questions = Question.all
render json: @questions
end
# GET /questions/1
def show
render json: @question
end
# POST /questions
def create
@question = Question.new(question_params)
authorize @question
if @question.save
render json: @question, status: :created, description: @question
else
render json: @question.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /questions/1
def update
if @question.update(question_params)
render json: @question
else
render json: @question.errors, status: :unprocessable_entity
end
end
# DELETE /questions/1
def destroy
@question.destroy
end
private
# Use callbacks to share common setup or constraints between actions.
def set_question
@question = Question.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def question_params
params.require(:question).permit(:description, :status)
end
def authorize!
authorize @question
end
end