Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MIS21
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Owen Ilagan
MIS21
Commits
a87fc111
Commit
a87fc111
authored
Jun 14, 2016
by
Owen Ilagan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Quiz
parent
fdcf6b76
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
42 deletions
+34
-42
welcome_controller.rb
app/controllers/welcome_controller.rb
+21
-26
quiz.html.erb
app/views/welcome/quiz.html.erb
+12
-15
routes.rb
config/routes.rb
+1
-1
No files found.
app/controllers/welcome_controller.rb
View file @
a87fc111
...
@@ -45,39 +45,34 @@ class WelcomeController < ApplicationController
...
@@ -45,39 +45,34 @@ class WelcomeController < ApplicationController
def
quiz
def
quiz
@score
=
'0'
@question
=
'0'
end
def
quiz_answer
@score
=
params
[
:score
]
@score
=
params
[
:score
]
if
@score
.
nil?
||
@score
.
empty?
@score
=
'0'
end
@question
=
params
[
:question
]
@question
=
params
[
:question
]
if
!
@question
.
nil?
if
@question
.
empty?
@question
=
'0'
end
if
@question
.
to_i
>
0
if
@question
.
to_i
>
0
correct_answer
=
getQuestions
[
@question
.
to_i
-
1
][
1
]
correct_answer
=
getQuestions
[
@question
.
to_i
-
1
][
1
]
@answer
=
params
[
:answer
]
@answer
=
params
[
:answer
]
if
!
@answer
.
nil?
&&
@answer
.
to_i
==
correct_answer
if
!
@answer
.
nil?
&&
@answer
.
to_i
==
correct_answer
@score
=
(
@score
.
to_i
+
1
).
to_s
@score
=
(
@score
.
to_i
+
1
).
to_s
end
end
length
=
getQuestions
.
size
if
@question
.
to_i
==
length
@question_text
=
'End of the quiz. You scored '
+
@score
+
' out of '
+
length
.
to_s
@question
=
'0'
@score
=
nil
else
@question_text
=
getQuestions
[
@question
.
to_i
][
0
]
@answers
=
getQuestions
[
@question
.
to_i
][
2
]
@question
=
(
@question
.
to_i
+
1
).
to_s
end
end
end
length
=
getQuestions
.
size
if
@question
.
to_i
==
length
@results
=
'End of the quiz. You scored '
+
@score
+
' out of '
+
length
.
to_s
@question
=
'0'
@score
=
'0'
else
else
@question
=
''
@question_text
=
getQuestions
[
@question
.
to_i
][
0
]
@answers
=
getQuestions
[
@question
.
to_i
][
2
]
@question
=
(
@question
.
to_i
+
1
).
to_s
end
end
render
'quiz'
end
end
private
private
...
...
app/views/welcome/quiz.html.erb
View file @
a87fc111
<div
class=
"jumbotron"
>
<div
class=
"jumbotron"
>
<div
class=
"container"
>
<div
class=
"container"
>
<h1>
Take a Quiz!
</h1>
<h1>
Take a Quiz!
</h1>
<%
if
@question
.
empty
?
%>
<%
if
!
@results
.
nil
?
%>
<p>
Test your general knowledge! Click START to begin the quiz.
</p>
<h2>
<%=
@results
%>
</h2>
<%
else
%>
<%
else
%>
<%
if
@question
==
'0'
%>
<%
if
@question
==
'0'
%>
<h2>
<%=
@question_text
%>
</h2>
<p>
Test your general knowledge! Click START to begin the quiz.
</p>
<%
else
%>
<%
else
%>
<h2>
Question #
<%=
@question
%>
</h2>
<h2>
Question #
<%=
@question
%>
</h2>
<p>
<%=
@question_text
%>
</p>
<p>
<%=
@question_text
%>
</p>
<%
end
%>
<%
end
%>
<%
end
%>
<%
end
%>
<p>
<p>
<%=
form_tag
(
"/quiz"
,
method:
"post"
)
do
%>
<%=
form_tag
(
"/quiz"
,
method:
"post"
)
do
%>
<%=
hidden_field
(
nil
,
:question
,
value:
@question
)
%>
<%=
hidden_field
(
nil
,
:question
,
value:
@question
)
%>
<%=
hidden_field
(
nil
,
:score
,
value:
@score
)
%>
<%=
hidden_field
(
nil
,
:score
,
value:
@score
)
%>
<%
if
@question
.
empty?
%>
<%
if
@question
==
'0'
%>
<input
class=
"btn btn-primary btn-lg"
type=
"submit"
value=
"Start »"
></input>
<input
class=
"btn btn-primary btn-lg"
type=
"submit"
value=
"Start »"
></input>
<%
else
%>
<%
else
%>
<%
if
@question
!=
'0'
%>
<ul
class=
"list-group"
>
<ul
class=
"list-group"
>
<%
@answers
.
each_with_index
do
|
item
,
index
|
%>
<%
@answers
.
each_with_index
do
|
item
,
index
|
%>
<li
class=
"list-group-item"
>
<li
class=
"list-group-item"
>
...
@@ -28,9 +26,8 @@
...
@@ -28,9 +26,8 @@
</li>
</li>
<%
end
%>
<%
end
%>
</ul>
</ul>
<%
end
%>
<%
if
@question
==
'0'
%>
<%
if
!
@results
.
nil?
%>
<input
class=
"btn btn-primary btn-lg"
type=
"submit"
value=
"Try Again »"
></input>
<input
class=
"btn btn-primary btn-lg"
type=
"submit"
value=
"Try Again »"
></input>
<%
else
%>
<%
else
%>
<input
class=
"btn btn-primary btn-lg"
type=
"submit"
value=
"Answer »"
></input>
<input
class=
"btn btn-primary btn-lg"
type=
"submit"
value=
"Answer »"
></input>
...
...
config/routes.rb
View file @
a87fc111
...
@@ -11,7 +11,7 @@ Rails.application.routes.draw do
...
@@ -11,7 +11,7 @@ Rails.application.routes.draw do
get
'random'
=>
'welcome#random'
get
'random'
=>
'welcome#random'
post
'random'
=>
'welcome#random'
post
'random'
=>
'welcome#random'
get
'quiz'
=>
'welcome#quiz'
get
'quiz'
=>
'welcome#quiz'
post
'quiz'
=>
'welcome#quiz'
post
'quiz'
=>
'welcome#quiz
_answer
'
# Example of named route that can be invoked with purchase_url(id: product.id)
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment