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
655ba07d
Commit
655ba07d
authored
Jul 18, 2016
by
Bianca Tarun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added candidates_controller
parent
1cf66a18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
6 deletions
+64
-6
candidates_controller.rb
Election/app/controllers/admin/candidates_controller.rb
+58
-0
positions_controller.rb
Election/app/controllers/admin/positions_controller.rb
+6
-6
No files found.
Election/app/controllers/admin/candidates_controller.rb
0 → 100644
View file @
655ba07d
module
Admin
class
CandidatesController
<
ApplicationController
before_action
:authenticate_user!
def
index
@candidates
=
Candidate
.
all
@positions
=
Postion
.
all
render
"admin/candidates/index.html.erb"
end
def
new
@position
=
Candidate
.
new
render
"admin/candidates/new.html.erb"
end
def
create
@candidate
=
Candidate
.
new
(
candidate_params
())
if
@position
.
save
redirect_to
admin_candidate_path
(
@candidate
.
id
)
else
render
"admin/candidates/new.html.erb"
end
end
def
update
@candidate
=
Candidate
.
find
(
params
[
:id
])
if
@candidate
.
update
(
candidate_params
())
redirect_to
admin_candidate_path
(
@candidate
.
id
)
else
render
"admin/candidate/edit.html.erb"
end
end
def
show
@candidate
=
Candidate
.
find
(
params
[
: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
def
destroy
@candidate
=
Candidate
.
find
(
params
[
:id
])
@votes
=
Vote
.
where
(
candidate_id:
(
@candidate
.
id
))
@votes
.
destroy_all
@candidate
.
destroy
redirect_to
admin_candidates_path
end
def
candidate_params
params
.
require
(
:candidate
).
permit!
end
end
end
\ No newline at end of file
Election/app/controllers/admin/positions_controller.rb
View file @
655ba07d
...
@@ -19,7 +19,7 @@ class PositionsController < ApplicationController
...
@@ -19,7 +19,7 @@ class PositionsController < ApplicationController
end
end
end
end
def
edit
def
edit
@position
=
Position
.
find
(
params
[
:id
])
@position
=
Position
.
find
(
params
[
:id
])
end
end
def
update
def
update
@position
=
Position
.
find
(
params
[
:id
])
@position
=
Position
.
find
(
params
[
:id
])
...
@@ -31,9 +31,9 @@ class PositionsController < ApplicationController
...
@@ -31,9 +31,9 @@ class PositionsController < ApplicationController
end
end
end
end
def
show
def
show
@position
=
Position
.
find
(
params
[
:id
])
@position
=
Position
.
find
(
params
[
:id
])
@candidates
=
Candidate
.
all
@candidates
=
Candidate
.
all
render
"admin/positions/show.html.erb"
render
"admin/positions/show.html.erb"
end
end
def
destroy
def
destroy
@position
=
Position
.
find
(
params
[
:id
])
@position
=
Position
.
find
(
params
[
:id
])
...
@@ -47,10 +47,10 @@ class PositionsController < ApplicationController
...
@@ -47,10 +47,10 @@ class PositionsController < ApplicationController
@position
.
destroy
@position
.
destroy
@candidates
.
destroy_all
@candidates
.
destroy_all
redirect_to
admin_positions_path
redirect_to
admin_positions_path
end
end
def
position_params
def
position_params
params
.
require
(
:position
).
permit!
params
.
require
(
:position
).
permit!
end
end
end
end
end
end
\ 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