Commit 720332d7 authored by royce-matthew's avatar royce-matthew

added images

parent a2dbb107
......@@ -37,4 +37,9 @@
.right
{
float:right;
}
.candidate-image {
border-radius: 50%;
border: 1px #e7e7e7 solid;
}
\ No newline at end of file
......@@ -12,4 +12,12 @@ class Candidate < ActiveRecord::Base
def full_name
"#{ self.first_name } #{ self.last_name }"
end
def image
if self.image_link == nil
"https://65.media.tumblr.com/avatar_19642255c98d_128.png"
else
self.image_link
end
end
end
\ No newline at end of file
......@@ -6,9 +6,8 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
has_many :votes
def list_of_positions
x = "hello"
end
def full_name
"#{self.first_name} #{self.last_name}"
end
end
......@@ -4,6 +4,7 @@
<%= f.association :position, label_method: :name, value_method: :id %>
<%= f.input :first_name%>
<%= f.input :last_name%>
<%= f.input :image_link%>
<%= f.input :slogan%>
<%= f.submit %>
<% end %>
......@@ -3,15 +3,15 @@
<%@positions.each do |p|%>
<div style="display:inline-block; padding:20px">
<h4><%=p.name%></h4>
<table style="width:300px;">
<thead><td>Name</td><td>Slogan</td><td>Votes</td></thead>
<table style="width:100%;">
<thead><td>&nbsp;</td><td>Name</td><td>Slogan</td><td>Votes</td><td>&nbsp;</td></thead>
<%total = 0%>
<%p.candidates.each do |c|%>
<%total = total+c.votes.count%>
<%end%>
<%p.candidates.each do |c|%>
<tr><td><%=link_to c.full_name, admin_candidate_path(c.id), {:style =>"font-size:15 px;"}%></td><td ><%=c.slogan%></td><td><%=c.votes.count%></td>
<tr><td><img class="candidate-image" style="background: url(<%=c.image%>); background-size:cover; background-position: 50% 50%; height:64px; width:64px; " width="64px" height="64px;"></td><td style="min-width: 250px;"><%=link_to c.full_name, admin_candidate_path(c.id), {:style =>"font-size:15 px;"}%></td><td style="min-width: 300px;"><%=c.slogan%></td><td><%=c.votes.count%></td>
<td> <progress value="<%=c.votes.count%>" max="<%=total%>" ></td>
</tr>
<%end%>
......
......@@ -5,17 +5,18 @@
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
-->
<br>
<td>Hello <%= current_user.email %></td>
<td>Hello <%= current_user.full_name %></td>
<br>
<br>
<ul>
<%@positions.each do |p|%>
<li> has user already voted for <%=p.name%>?<br>
<li> <%=p.name%><br>
<%voted_for = false%>
<% p.candidates.each do |c|%>
<%c.votes.each do |v|%>
<%if v.user_id == current_user.id%>
You have already voted for <%= v.candidate.full_name%>
<%voted_for = true%>
<% end %>
<%end%>
......@@ -25,7 +26,7 @@
<%if !voted_for%>
<%=link_to "Vote for a #{p.name}", "/voting/new/#{p.id}" %>
<%else%>
You have already Voted for a <%= p.name%>
<%end%>
</li>
......
class AddingPhotoLinkToCandidate < ActiveRecord::Migration[5.0]
def change
add_column :candidates, :image_link, :string
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160718145025) do
ActiveRecord::Schema.define(version: 20160719070050) do
create_table "candidates", force: :cascade do |t|
t.string "first_name"
......@@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 20160718145025) do
t.integer "position_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_link"
end
create_table "positions", force: :cascade do |t|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment