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
5e8443b6
Commit
5e8443b6
authored
Jul 20, 2016
by
Bianca Tarun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edited votes controller
parent
2cc6b35b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
20 deletions
+14
-20
votes_controller.rb
Election/app/controllers/votes_controller.rb
+12
-19
vote.rb
Election/app/models/vote.rb
+1
-0
_form.html.erb
Election/app/views/votes/_form.html.erb
+1
-1
No files found.
Election/app/controllers/votes_controller.rb
View file @
5e8443b6
class
VotesController
<
ApplicationController
before_action
:authenticate_user!
def
index
@positions
=
Position
.
all
@votes
=
current_user
.
votes
@candidates
=
Candidate
.
all
@candidates_by_position
=
Candidate
.
all
.
group_by
(
&
:position_id
)
end
def
new
if
Vote
.
exists?
(
user:
current_user
)
redirect_to
root_path
,
alert:
"You have already voted."
else
@user
=
current_user
@user
.
votes
.
build
@user
=
current_user
.
votes
.
build
@positions
=
Position
.
all
render
"votes/new.html.erb"
end
end
def
checkout
if
current_user
.
update
(
vote_params
)
redirect_to
root_path
...
...
@@ -26,17 +24,12 @@ class VotesController < ApplicationController
end
def
profile
if
user_signed_in?
@user
=
current_user
@votes
=
Vote
.
where
(
user_id:
(
@user
.
id
))
else
redirect_to
root_path
end
@votes
=
current_user
.
votes
end
private
def
vote_params
params
.
require
(
:
vote
).
permit!
params
.
require
(
:
user
).
permit!
end
end
\ No newline at end of file
Election/app/models/vote.rb
View file @
5e8443b6
...
...
@@ -5,4 +5,5 @@ class Vote < ActiveRecord::Base
def
to_s
"
#{
candidate
.
first_name
}
#{
candidate
.
last_name
}
"
end
accepts_nested_attributes_for
:votes
end
Election/app/views/votes/_form.html.erb
View file @
5e8443b6
...
...
@@ -23,7 +23,7 @@
<%=
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
<%=
link_to
"Vote Record"
,
votes_index_path
%>
<%
end
%>
<script>
...
...
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