Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
final_project
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
AkosiCrux
final_project
Commits
17007a01
Commit
17007a01
authored
Jul 18, 2016
by
Paulo Macasaet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
magic vote
parent
a8dcba67
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
92 additions
and
5 deletions
+92
-5
votes_controller.rb
elect/app/controllers/votes_controller.rb
+38
-0
candidate.rb
elect/app/models/candidate.rb
+4
-0
user.rb
elect/app/models/user.rb
+2
-0
vote.rb
elect/app/models/vote.rb
+5
-0
index.html.erb
elect/app/views/admin/candidates/index.html.erb
+1
-1
index.html.erb
elect/app/views/candidates/index.html.erb
+2
-1
new.html.erb
elect/app/views/devise/registrations/new.html.erb
+1
-1
index.html.erb
elect/app/views/pages/index.html.erb
+1
-2
_form.html.erb
elect/app/views/votes/_form.html.erb
+6
-0
index.html.erb
elect/app/views/votes/index.html.erb
+16
-0
new.html.erb
elect/app/views/votes/new.html.erb
+5
-0
show.html.erb
elect/app/views/votes/show.html.erb
+9
-0
routes.rb
elect/config/routes.rb
+2
-0
No files found.
elect/app/controllers/votes_controller.rb
0 → 100644
View file @
17007a01
class
VotesController
<
ApplicationController
def
index
@votes
=
Vote
.
all
@positions
=
Position
.
all
render
"votes/index.html.erb"
end
def
new
@vote
=
Vote
.
new
render
"votes/new.html.erb"
end
def
create
@vote
=
Vote
.
new
(
vote_params
())
if
@vote
.
save
redirect_to
vote_path
(
@vote
.
id
)
else
render
"votes/new.html.erb"
end
end
def
show
@candidate
=
Candidate
.
find
(
params
[
:id
])
@vote
=
Vote
.
find
(
params
[
:id
])
render
"votes/show.html.erb"
end
def
vote_params
params
.
require
(
:vote
).
permit!
end
end
\ No newline at end of file
elect/app/models/candidate.rb
View file @
17007a01
...
...
@@ -6,4 +6,8 @@ class Candidate < ActiveRecord::Base
belongs_to
:position
has_many
:votes
def
to_s
"
#{
first_name
}
#{
last_name
}
"
end
end
elect/app/models/user.rb
View file @
17007a01
...
...
@@ -4,4 +4,6 @@ class User < ActiveRecord::Base
devise
:database_authenticatable
,
:registerable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
has_many
:votes
end
elect/app/models/vote.rb
View file @
17007a01
class
Vote
<
ActiveRecord
::
Base
belongs_to
:candidate
belongs_to
:user
def
to_s
"
#{
first_name
}
"
end
end
elect/app/views/admin/candidates/index.html.erb
View file @
17007a01
...
...
@@ -2,7 +2,7 @@
<%=
link_to
(
"Add Candidate"
,
new_admin_candidate_path
)
%>
<table
width=
"70%"
>
<table
width=
"70%"
,
align=
"center"
>
<tr>
<th>
Position
</th>
<th>
First Name
</th>
...
...
elect/app/views/candidates/index.html.erb
View file @
17007a01
<h1
style=
"text-align:center"
>
Here are the Candidates
</h1>
<%=
link_to
"See Total Vote Count"
,
votes_path
%>
<table
width=
"70%"
>
<table
width=
"70%"
,
align=
"center"
>
<tr>
<th>
Position
</th>
<th>
First Name
</th>
...
...
elect/app/views/devise/registrations/new.html.erb
View file @
17007a01
...
...
@@ -9,7 +9,7 @@
<%=
f
.
input
:password_confirmation
,
required:
true
%>
<%=
f
.
input
:first_name
,
required:
true
%>
<%=
f
.
input
:last_name
,
required:
true
%>
<%=
f
.
input
:birthday
,
required:
true
%>
<%=
f
.
input
:birthday
,
required:
true
,
start_year:
1930
,
end_year:
1998
%>
<%=
f
.
input
:gender
,
as: :select
,
collection:
[
"Male"
,
"Female"
],
required:
true
%>
</div>
...
...
elect/app/views/pages/index.html.erb
View file @
17007a01
<h1>
Candidates
</h1>
<%=
link_to
"The Candidates (USER)"
,
candidates_path
%>
<%=
link_to
"See Total Vote Count"
,
votes_path
%>
<a
href =
"/about"
>
About
</a>
...
...
elect/app/views/votes/_form.html.erb
0 → 100644
View file @
17007a01
<%=
simple_form_for
(
@vote
)
do
|
f
|
%>
<%=
f
.
association
:candidate
%>
<%=
f
.
input
:comments
%>
<%=
f
.
submit
%>
<%
end
%>
\ No newline at end of file
elect/app/views/votes/index.html.erb
0 → 100644
View file @
17007a01
<h1>
Total Votes
</h1>
<%=
link_to
"Vote Here!"
,
new_vote_path
%>
<%=
link_to
"The Candidates (USER)"
,
candidates_path
%>
<%
@positions
.
each
do
|
c
|
%>
<h2>
(
<%=
c
.
id
%>
)
<%=
c
.
name
%>
</h2>
<ul>
<%
c
.
candidates
.
each
do
|
p
|
%>
<li>
<%=
link_to
p
.
last_name
,
candidate_path
(
p
.
id
)
%>
</li>
<%
end
%>
</ul>
<%
end
%>
<%=
link_to
(
"Back to Home"
,
root_path
)
%>
\ No newline at end of file
elect/app/views/votes/new.html.erb
0 → 100644
View file @
17007a01
<h1>
VOTE HERE
</h1>
<%=
render
partial:
"form"
%>
<%=
link_to
"Back to Vote Summary"
,
votes_path
%>
elect/app/views/votes/show.html.erb
0 → 100644
View file @
17007a01
<h1>
Vote Summary
</h1>
<h2>
I voted for
</h2>
<h4>
<%=
@vote
.
id
%>
</h4>
<h4>
<%=
@candidate
.
nickname
%>
</h4>
<h4>
<%=
@vote
.
comments
%>
</h4>
<%=
link_to
"Back to votes"
,
votes_path
%>
elect/config/routes.rb
View file @
17007a01
...
...
@@ -4,6 +4,8 @@ Rails.application.routes.draw do
get
"/about"
,
to:
"pages#about"
resources
:candidates
get
"/positions/:id"
,
to:
"positions#show"
resources
:votes
namespace
:admin
do
resources
:candidates
...
...
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