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

added images

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