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
4013142a
Commit
4013142a
authored
Jul 19, 2016
by
Kristoff Sison
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.discs.ateneo.edu/deankristianb/MIS21FinalsElection
parents
2f546dba
ad30be84
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
120 additions
and
9 deletions
+120
-9
votes_controller.rb
Election/app/controllers/votes_controller.rb
+57
-1
candidate.rb
Election/app/models/candidate.rb
+3
-0
vote.rb
Election/app/models/vote.rb
+3
-0
_form.html.erb
Election/app/views/admin/candidates/_form.html.erb
+2
-2
index.html.erb
Election/app/views/admin/candidates/index.html.erb
+4
-1
show.html.erb
Election/app/views/admin/candidates/show.html.erb
+3
-3
index.html.erb
Election/app/views/votes/index.html.erb
+3
-2
new.html.erb
Election/app/views/votes/new.html.erb
+14
-0
show.html.erb
Election/app/views/votes/show.html.erb
+31
-0
No files found.
Election/app/controllers/votes_controller.rb
View file @
4013142a
class
VotesController
<
ApplicationController
def
index
@votes
=
Vote
.
all
@votes
=
current_user
.
votes
@candidates
=
Candidate
.
all
@positions
=
Position
.
all
render
"votes/index.html.erb"
end
def
new
@positions
=
Position
.
all
@vote
=
Vote
.
new
@candidates
=
[]
@all_candidates
=
Candidate
.
pluck
(
:id
)
@candidate_voted
=
current_user
.
votes
.
pluck
(
:candidate_id
).
uniq
@all_candidates
.
each
do
|
candidate
|
@candidate_voted
.
each
do
|
voted
|
if
candidate
=
voted
@all_candidates
.
delete
(
candidate
)
end
end
end
@all_candidates
.
each
do
|
c1
|
@candidates
.
push
(
Candidate
.
find
(
c1
))
end
if
@candidates
.
empty?
redirect_to
root_path
,
notice:
"You have already voted all candidates"
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
=>
'show'
end
end
def
update
end
def
show
@positions
=
Position
.
all
@votes
=
current_user
.
votes
@candidates
=
Candidate
.
all
end
def
vote_params
params
.
require
(
:vote
).
permit!
end
end
\ No newline at end of file
Election/app/models/candidate.rb
View file @
4013142a
...
...
@@ -4,4 +4,7 @@ class Candidate < ActiveRecord::Base
validates
:slogan
,
uniqueness:
true
,
presence:
true
belongs_to
:position
has_many
:votes
def
to_s
"
#{
first_name
}
#{
last_name
}
"
end
end
Election/app/models/vote.rb
View file @
4013142a
...
...
@@ -2,4 +2,7 @@ class Vote < ActiveRecord::Base
belongs_to
:user
belongs_to
:candidate
validates
:candidate_id
,
presence:
true
def
to_s
"
#{
candidate
.
first_name
}
#{
candidate
.
last_name
}
"
end
end
Election/app/views/admin/candidates/_form.html.erb
View file @
4013142a
...
...
@@ -2,7 +2,7 @@
<%=
f
.
input
:first_name
%>
<%=
f
.
input
:last_name
%>
<%=
f
.
input
:nickname
%>
<%=
f
.
association
:position
%>
<%=
f
.
input
:slogan
%>
<%=
f
.
association
:position
,
include_blank:
false
%>
<%=
f
.
input
:slogan
%>
<%=
f
.
submit
%>
<%
end
%>
\ No newline at end of file
Election/app/views/admin/candidates/index.html.erb
View file @
4013142a
...
...
@@ -4,12 +4,15 @@
<hr>
<%
@positions
.
each
do
|
p
|
%>
<h2>
<%=
p
.
name
%>
</h2>
<ul>
<%
p
.
candidates
.
each
do
|
candidate
|
%>
</ul>
<ul>
<%
p
.
candidates
.
each
do
|
candidate
|
%>
<li>
<%=
candidate
.
first_name
%>
<%=
candidate
.
last_name
%>
<%=
link_to
"Show"
,
admin_candidate_path
(
candidate
.
id
)
%>
<%=
link_to
"Edit"
,
edit_admin_candidate_path
(
candidate
.
id
)
%>
<%=
link_to
"Delete"
,
admin_candidate_path
(
candidate
.
id
),
method: :delete
,
data:
{
confirm:
'Are you sure?'
}
%>
</li>
<%
end
%>
</ul>
<%
end
%>
Election/app/views/admin/candidates/show.html.erb
View file @
4013142a
<h2>
Candidate:
<%=
@candidate
.
first_name
%>
<%=
@candidate
.
last_name
%>
</h2>
<h3>
<%=
@candidate
.
slogan
%>
</h3>
<ul>
<li>
Votes:
<%
@votes_male
.
size
+
@votes_female
.
size
%>
</li>
<li>
Male Voters:
<%
@votes_male
.
size
%>
</li>
<li>
Female Voters:
<%
@votes_female
.
size
%>
</li>
<li>
Votes:
<%
=
@votes_male
.
size
+
@votes_female
.
size
%>
</li>
<li>
Male Voters:
<%
=
@votes_male
.
size
%>
</li>
<li>
Female Voters:
<%
=
@votes_female
.
size
%>
</li>
</ul>
<%=
link_to
"Back to Candidates"
,
admin_candidates_path
%>
\ No newline at end of file
Election/app/views/votes/index.html.erb
View file @
4013142a
<h1>
Votes
</h1>
<%=
link_to
"Vote Now!"
,
new_vote_path
%>
<table
width=
"100%"
>
<tr>
<th>
#
</th>
...
...
@@ -7,12 +7,13 @@
<th>
Candidate
</th>
<th>
Position
</th>
</tr>
<%
@votes
.
each
do
|
vote
|
%>
<tr>
<td>
<%=
link_to
"
#{
vote
.
id
}
"
,
vote_path
(
vote
.
id
)
%>
</td>
<td>
<%=
vote
.
user_id
%>
</td>
<td>
<%=
vote
.
candidate
.
first_name
%>
"
<%=
vote
.
candidate
.
nickname
%>
"
<%=
vote
.
candidate
.
last_name
%>
<%=
vote
.
candidate
.
first_name
%>
"
<%=
vote
.
candidate
.
nickname
%>
"
<%=
vote
.
candidate
.
last_name
%>
</td>
<td>
<%=
vote
.
candidate
.
position
.
name
%>
...
...
Election/app/views/votes/new.html.erb
0 → 100644
View file @
4013142a
<h1>
Vote
</h1>
<%=
simple_form_for
(
@vote
)
do
|
v
|
%>
<%
@positions
.
each
do
|
p
|
%>
<h2>
<%=
p
.
name
%>
</h2>
<%=
v
.
association
:candidate
,
:collection
=>
Candidate
.
where
(
position_id:
(
p
.
id
)),
include_blank:
false
%>
<%=
v
.
input
:comments
%>
<br>
<%=
v
.
button
:submit
,
"Vote"
%>
<%
end
%>
<%
end
%>
Election/app/views/votes/show.html.erb
0 → 100644
View file @
4013142a
<h1>
My Vote Record
</h1>
<table
class=
"table"
>
<thead>
<th>
Candidate
</th>
<th>
Position
</th>
<th>
Comments
</th>
</thead>
<tbody>
<%
if
!
@votes
.
empty?
%>
<%
@positions
.
each
do
|
positions
|
%>
<%
current_user
.
votes
.
each
do
|
blah
|
%>
<%
@candidates
.
each
do
|
candidates
|
%>
<%
if
candidates
.
position
.
name
==
positions
.
name
%>
<tr>
<td>
<%=
candidates
.
first_name
%>
<%=
candidates
.
last_name
%>
</td>
<td>
<%=
candidates
.
position
.
name
%>
</td>
<td>
<%=
blah
.
comments
%>
</td>
</tr>
<%
end
%>
<%
end
%>
<%
end
%>
<%
end
%>
<%
else
%>
<tr>
<td
colspan=
"3"
><em>
No Votes Found
</em></td>
</tr>
<%
end
%>
</tbody>
</table>
<a
href=
"http://localhost:3000/votes/new"
class=
"btn btn-primary"
role=
"button"
>
Add Vote
</a>
\ No newline at end of file
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