Created
July 14, 2013 18:53
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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