Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MIS21FinalsElection
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
Dean Krisitan Bardeloza
MIS21FinalsElection
Commits
3b5c25a4
Commit
3b5c25a4
authored
Jul 21, 2016
by
Dean Krisitan Bardeloza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added links to show for candidates
parent
3df41415
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
33 deletions
+42
-33
candidates_controller.rb
Election/app/controllers/candidates_controller.rb
+14
-0
votes_controller.rb
Election/app/controllers/votes_controller.rb
+13
-0
index.html.erb
Election/app/views/candidates/index.html.erb
+4
-1
show.html.erb
Election/app/views/candidates/show.html.erb
+1
-1
index.html.erb
Election/app/views/pages/index.html.erb
+3
-1
_form.html.erb
Election/app/views/votes/_form.html.erb
+7
-30
No files found.
Election/app/controllers/candidates_controller.rb
View file @
3b5c25a4
...
...
@@ -6,4 +6,18 @@ class CandidatesController < ApplicationController
render
"candidates/index.html.erb"
end
def
show
@candidate
=
Candidate
.
find
(
params
[
:id
])
@party_list
=
PartyList
.
where
(
candidate_id:
(
@candidate
.
id
))
@votes
=
Vote
.
where
(
candidate_id:
(
@candidate
.
id
))
@votes_male
=
Array
.
new
@votes_female
=
Array
.
new
@votes
.
each
do
|
vote
|
if
vote
.
user
.
gender
==
"Male"
@votes_male
.
push
(
vote
)
else
@votes_female
.
push
(
vote
)
end
end
end
end
\ No newline at end of file
Election/app/controllers/votes_controller.rb
View file @
3b5c25a4
...
...
@@ -9,10 +9,23 @@ class VotesController < ApplicationController
redirect_to
root_path
,
alert:
"You have already voted."
else
@user
=
current_user
.
votes
.
build
@vote
=
Vote
.
new
@positions
=
Position
.
all
end
end
def
create
@candidate
=
Candidate
.
find
(
vote_params
[
:candidate_id
])
@vote
=
Vote
.
new
(
vote_params
)
@vote
.
user
=
current_user
if
@vote
.
save
redirect_to
root_path
else
render
:action
=>
'new'
end
end
def
checkout
if
current_user
.
update
(
vote_params
)
redirect_to
root_path
...
...
Election/app/views/candidates/index.html.erb
View file @
3b5c25a4
...
...
@@ -6,7 +6,10 @@
<th>
Full Name
</th>
</tr>
<%
p
.
candidates
.
each
do
|
candidate
|
%>
<td>
<%=
candidate
.
first_name
%>
<%=
candidate
.
last_name
%>
</td>
<tr>
<td>
<%=
candidate
.
first_name
%>
<%=
candidate
.
last_name
%>
</td>
<td>
<%=
link_to
"Show"
,
candidate_path
(
candidate
.
id
)
%>
</td>
</tr>
<%
end
%>
</table>
<%
end
%>
Election/app/views/candidates/show.html.erb
View file @
3b5c25a4
...
...
@@ -16,4 +16,4 @@
</li>
<%
end
%>
</ul>
<%=
link_to
"Back to Candidates"
,
admin_candidates_path
%>
\ No newline at end of file
<%=
link_to
"Back to Candidates"
,
candidates_path
%>
\ No newline at end of file
Election/app/views/pages/index.html.erb
View file @
3b5c25a4
...
...
@@ -24,8 +24,10 @@
<th>
Number of Votes
</th>
</tr>
<%
p
.
candidates
.
each
do
|
candidate
|
%>
<td>
<%=
candidate
.
first_name
%>
<%=
candidate
.
last_name
%>
</td>
<tr>
<td>
<%=
link_to
"
#{
candidate
.
first_name
}
#{
candidate
.
last_name
}
"
,
candidate_path
(
candidate
.
id
)
%>
</td>
<td>
<%=
Vote
.
where
(
candidate_id:
candidate
.
id
).
count
%>
</td>
</tr>
<%
end
%>
</table>
<%
end
%>
...
...
Election/app/views/votes/_form.html.erb
View file @
3b5c25a4
<h1>
Vote for your candidates.
</h1>
<%=
simple_form_for
(
@user
,
url:
checkout_path
,
method: :post
)
do
|
v
|
%>
<%
@positions
.
each
do
|
p
|
%>
<%=
v
.
simple_fields_for
:votes
do
|
f
|
%>
<h2>
<%=
p
.
name
%>
</h2>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
<%=
f
.
association
:candidate
,
:collection
=>
Candidate
.
where
(
position_id:
(
p
.
id
)),
include_blank:
false
,
:label_method
=>
lambda
{
|
candidate
|
"
#{
candidate
.
last_name
}
,
#{
candidate
.
first_name
}
"
},
as: :radio_buttons
,
label:
"Candidates: "
%>
<%
Candidate
.
where
(
position_id:
(
p
.
id
)).
each
do
|
candidate
|
%>
<p><div
class=
"btn btn-primary btn-xs"
data-toggle=
"popover"
data-content=
"
<%=
candidate
.
slogan
%>
"
style=
"margin-top: 2px; margin-bottom: 1px"
,
data-trigger=
"focus"
,
role=
"button"
,
tabindex=
"0"
,
title=
"
<%=
candidate
.
first_name
%>
<%=
candidate
.
last_name
%>
"
>
View
<%=
candidate
.
last_name
%>
's Slogan
</div></p>
<%
end
-%>
</div>
<div
class=
"col-md-6"
>
<br><br><br>
</div>
</div>
<%=
f
.
input
:comments
%>
<%
end
-%>
<%
end
-%>
<%=
v
.
button
:submit
,
"Vote"
,
class:
"btn btn-primary"
%>
<%=
link_to
"Back to Homepage"
,
root_path
,
class:
"btn btn-default"
%>
<%=
link_to
"Vote Record"
,
votes_index_path
%>
<%
end
%>
<%=
simple_form_for
@vote
do
|
v
|
%>
<%=
v
.
association
:candidate
,
include_blank:
false
,
collection:
@candidates
%>
<%=
v
.
input
:comments
%>
<br>
<script>
$
(
document
).
ready
(
function
(){
$
(
'[data-toggle="popover"]'
).
popover
();
});
</script>
\ No newline at end of file
<%=
v
.
button
:submit
,
"Submit"
%>
<%
end
%>
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