Class: Api::AnswersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/answers_controller.rb

Instance Method Summary collapse

Methods included from Response

#json_response

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/api/answers_controller.rb', line 8

def create
  answer = Answer.new(answer_params)

  if answer.save
    render json: answer, status: :created
  else
    render json: answer.errors.full_messages, status: :unprocessable_entity
  end
end

#destroyObject



18
19
20
21
22
# File 'app/controllers/api/answers_controller.rb', line 18

def destroy
  @answer.destroy

  render status: :ok
end

#updateObject



24
25
26
27
28
29
30
# File 'app/controllers/api/answers_controller.rb', line 24

def update
  if @answer.update(answer_params)
    render @answer, status: :ok
  else
    render json: @answer.errors.full_messages, status: :unprocessable_entity
  end
end