Merge branch 'cleanup'

This commit is contained in:
Juanjo Bazán
2015-07-18 21:59:41 +02:00
9 changed files with 31 additions and 36 deletions

View File

@@ -1,6 +0,0 @@
class WelcomeController < ApplicationController
def index
end
end

View File

@@ -4,4 +4,8 @@ module ApplicationHelper
debate.tag_list.map { |tag| link_to sanitize(tag), debates_path(tag: tag) }.join(', ').html_safe debate.tag_list.map { |tag| link_to sanitize(tag), debates_path(tag: tag) }.join(', ').html_safe
end end
def percentage(vote, debate)
return if debate.total_votes == 0
debate.send(vote).percent_of(debate.total_votes).to_s + "%"
end
end end

View File

@@ -12,12 +12,6 @@ class Debate < ActiveRecord::Base
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
#vote can be 'likes' or 'dislikes'
def percentage(vote)
return if total_votes == 0
send(vote).percent_of(total_votes)
end
def likes def likes
get_likes.size get_likes.size
end end

View File

@@ -1,38 +1,40 @@
<div id="debate-<%= @debate.id %>"> <span id="debate-<%= @debate.id %>" style="width:70%; float:left">
<p><%= @debate.title %></p> <p><%= @debate.title %></p>
<p><%= @debate.description %></p> <p><%= @debate.description %></p>
<p> <p>
Creado el: <%= l @debate.created_at.to_date %> Creado el: <%= l @debate.created_at.to_date %>
por: <%= @debate.author.name %> por: <%= @debate.author.name %>
</p> </p>
</div> </span>
<div> <span style="width:30%;float:left">
<div id='in_favor'> <div id='in_favor'>
<%= link_to "up", debate_votes_path(@debate, value: 'yes'), method: "post" %> <%= link_to "up", debate_votes_path(@debate, value: 'yes'), method: "post" %>
<%= @debate.percentage('likes') %>% <%= percentage('likes', @debate) %>
</div> </div>
<div id='against'> <div id='against'>
<%= link_to "down", debate_votes_path(@debate, value: 'no'), method: "post" %> <%= link_to "down", debate_votes_path(@debate, value: 'no'), method: "post" %>
<%= @debate.percentage('dislikes') %>% <%= percentage('dislikes', @debate) %>
</div> </div>
Votos <%= @debate.total_votes %> Votos <%= @debate.total_votes %>
</span>
<div style="display: block; width:300px">
<%= render 'shared/tags', debate: @debate %>
</div> </div>
<br/><br/> <br/><br/>
<%= render 'shared/tags', debate: @debate %>
<br/><br/>
Deja tu comentario
<%= render 'comments/form', parent: @debate %>
<div id="comments" style="padding-top:20px"> <div id="comments" style="padding-top:20px">
<h2>Comentarios</h2> <h2>Comentarios</h2>
<%= render @debate.root_comments %> <%= render @debate.root_comments %>
</div> </div>
Deja tu comentario
<%= render 'comments/form', parent: @debate %>
<br/><br/> <br/><br/>
<%= link_to 'Edit', edit_debate_path(@debate) %> | <%= link_to 'Edit', edit_debate_path(@debate) %> |
<%= link_to 'Back', debates_path %> <%= link_to 'Back', debates_path %>

View File

@@ -1,3 +1,4 @@
<div style="float:right; margin-right:50px">
<% if user_signed_in? %> <% if user_signed_in? %>
<li> <li>
<%= link_to('Logout', destroy_user_session_path, method: :delete) %> <%= link_to('Logout', destroy_user_session_path, method: :delete) %>
@@ -7,3 +8,4 @@
<%= link_to('Login', new_user_session_path) %> <%= link_to('Login', new_user_session_path) %>
</li> </li>
<% end %> <% end %>
</div>

View File

@@ -11,7 +11,7 @@
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %> <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body style="margin-left:50px"> <body style="margin:50px">
<p class="alert"><%= notice %></p> <p class="alert"><%= notice %></p>
<p class="alert"><%= alert %></p> <p class="alert"><%= alert %></p>

View File

@@ -1 +0,0 @@
<h1>Bienvenido al Ayuntamiento de Madrid</h1>

View File

@@ -5,7 +5,7 @@ Rails.application.routes.draw do
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root" # You can have the root of your site routed with "root"
root 'welcome#index' root 'debates#index'
resources :debates do resources :debates do
resources :votes, only: :create resources :votes, only: :create
resources :comments, only: :create resources :comments, only: :create

View File

@@ -4,7 +4,7 @@ feature "Home" do
scenario "Welcome message" do scenario "Welcome message" do
visit '/' visit '/'
expect(page).to have_content 'Bienvenido al Ayuntamiento de Madrid' expect(page).to have_content 'Debates sobre Madrid'
end end
end end