Created
January 19, 2014 19:35
-
-
Save davidedicillo/8509915 to your computer and use it in GitHub Desktop.
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
| def create | |
| @question = Question.find(params[:question_id]) | |
| @answer = @question.answers.create(params[:answer].permit(:option, :user_id, :question_id)) | |
| @nextquestion = Question.where.not(user_id: current_user.id).last | |
| @index = 0 | |
| while @nextquestion.answers.where(:user_id => current_user.id).count != 0 && @index < Question.all.count do | |
| @index = @index + 1 | |
| @nextquestion = Question.all[-@index] | |
| end | |
| redirect_to question_path(@nextquestion) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is probably a better way with just a single query, but this at least is more readable.