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
Hide 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
class
VotesController
<
ApplicationController
before_action
:authenticate_user!
before_action
:authenticate_user!
def
index
def
index
@positions
=
Position
.
all
@candidates_by_position
=
Candidate
.
all
.
group_by
(
&
:position_id
)
@votes
=
current_user
.
votes
end
@candidates
=
Candidate
.
all
end
def
new
def
new
if
Vote
.
exists?
(
user:
current_user
)
if
Vote
.
exists?
(
user:
current_user
)
redirect_to
root_path
,
alert:
"You have already voted."
redirect_to
root_path
,
alert:
"You have already voted."
else
else
@user
=
current_user
@user
=
current_user
.
votes
.
build
@user
.
votes
.
build
@positions
=
Position
.
all
@positions
=
Position
.
all
render
"votes/new.html.erb"
end
end
end
end
def
checkout
def
checkout
if
current_user
.
update
(
vote_params
)
if
current_user
.
update
(
vote_params
)
redirect_to
root_path
redirect_to
root_path
...
@@ -26,17 +24,12 @@ class VotesController < ApplicationController
...
@@ -26,17 +24,12 @@ class VotesController < ApplicationController
end
end
def
profile
def
profile
if
user_signed_in?
@votes
=
current_user
.
votes
@user
=
current_user
@votes
=
Vote
.
where
(
user_id:
(
@user
.
id
))
else
redirect_to
root_path
end
end
end
private
private
def
vote_params
def
vote_params
params
.
require
(
:
vote
).
permit!
params
.
require
(
:
user
).
permit!
end
end
end
end
\ No newline at end of file
Election/app/models/vote.rb
View file @
5e8443b6
...
@@ -5,4 +5,5 @@ class Vote < ActiveRecord::Base
...
@@ -5,4 +5,5 @@ class Vote < ActiveRecord::Base
def
to_s
def
to_s
"
#{
candidate
.
first_name
}
#{
candidate
.
last_name
}
"
"
#{
candidate
.
first_name
}
#{
candidate
.
last_name
}
"
end
end
accepts_nested_attributes_for
:votes
end
end
Election/app/views/votes/_form.html.erb
View file @
5e8443b6
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
<%=
v
.
button
:submit
,
"Vote"
,
class:
"btn btn-primary"
%>
<%=
v
.
button
:submit
,
"Vote"
,
class:
"btn btn-primary"
%>
<%=
link_to
"Back to Homepage"
,
root_path
,
class:
"btn btn-default"
%>
<%=
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
%>
<%
end
%>
<script>
<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