Method: AnswersController#create

Defined in:
app/controllers/answers_controller.rb

#createObject

POST /answers POST /answers.json



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/answers_controller.rb', line 91

def create
  @answer = Answer.new(answer_params)
  @answer.user = current_user
  unless @answer.question
    redirect_to questions_url
    return
  end

  respond_to do |format|
    if @answer.save
      flash[:notice] = t('controller.successfully_created', model: t('activerecord.models.answer'))
      format.html { redirect_to @answer }
      format.json { render json: @answer, status: :created, location: answer_url(@answer) }
    else
      format.html { render action: "new" }
      format.json { render json: @answer.errors, status: :unprocessable_entity }
    end
  end
end