Skip to content

Instantly share code, notes, and snippets.

@acconrad
Created July 14, 2013 18:53
Show Gist options
  • Save acconrad/5995347 to your computer and use it in GitHub Desktop.
Save acconrad/5995347 to your computer and use it in GitHub Desktop.
@user_answer needs model association (http://rails-bestpractices.com/posts/2-use-model-association)
begin
@user_answer = @user.user_answers.where(:question_id => @question_id).first
if @user_answer
@user_answer.answer_id = @answer_id
@user_answer.save!
@message = 'Answer updated successfully!'
else
@user.user_answers.create(:question_id => params[:questionId], :answer_id => params[:answerId])
@message = 'Answer submitted successfully!'
end
rescue ex
@message = ex.message.split(':')[1].chomp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment