New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Quizzes #1289
Merged
Merged
Introduce Quizzes #1289
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.questions-show { | ||
.hidden { | ||
display: none; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class QuestionsController < ApplicationController | ||
def show | ||
@quiz = find_quiz | ||
@question = find_question | ||
end | ||
|
||
private | ||
|
||
def find_question | ||
Question.find(params[:id]) | ||
end | ||
|
||
def find_quiz | ||
Quiz.find(params[:quiz_id]) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class QuizzesController < ApplicationController | ||
def show | ||
redirect_to quiz_question_path(quiz, quiz.first_question) | ||
end | ||
|
||
private | ||
|
||
def quiz | ||
Quiz.find(params[:id]) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Question < ActiveRecord::Base | ||
validates :prompt, presence: true | ||
validates :answer, presence: true | ||
|
||
belongs_to :quiz | ||
|
||
acts_as_list scope: :quiz | ||
|
||
def next | ||
lower_item | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Quiz < ActiveRecord::Base | ||
validates :title, presence: true | ||
|
||
has_many :questions, -> { order(position: :asc) }, dependent: :destroy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test for it. |
||
|
||
def first_question | ||
questions.first | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if current_user.has_access_to?(:quizzes) %> | ||
<h2><%= t('.quizzes-list-title') %></h2> | ||
<section class="quizzes"> | ||
<%= render quizzes %> | ||
</section> | ||
<% end %> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<div class="question"> | ||
<h1> | ||
<%= t('.numbered-title', position: @question.position) %> | ||
</h1> | ||
|
||
<div class="prompt"> | ||
<%= format_markdown @question.prompt %> | ||
</div> | ||
|
||
<h3><%= t('.answer') %></h3> | ||
|
||
<%= link_to t('.reveal-answer'), "javascript:;", class: "reveal-answer" %> | ||
|
||
<div class="answer hidden"> | ||
<%= format_markdown @question.answer %> | ||
|
||
<% if @question.next.present? %> | ||
<%= link_to t('.next-question'), [@question.quiz, @question.next] %> | ||
<% else %> | ||
<p>No more questions.</p> | ||
<%= link_to t('.return-to-dashboard'), practice_path %> | ||
<% end %> | ||
</div> | ||
|
||
<% content_for :javascript do -%> | ||
<script type="text/javascript"> | ||
$(function() { | ||
$revealAnswerLink = $(".reveal-answer"); | ||
$revealAnswerLink.on("click", function(event) { | ||
$(".answer").show(); | ||
$revealAnswerLink.hide(); | ||
}); | ||
}); | ||
</script> | ||
<% end %> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="quiz"> | ||
<span class="title"><%= link_to quiz.title, quiz %></span> | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to continue to pass both objects in here, or would it make sense to create a facade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the template, nearly all the methods are called directly on the
@question
object so it feels a wee bit premature to extract a facade now, but I expect that will change soon.