From afdb0980b078dbe660edab38af877b91f065951e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 18 Jul 2015 21:27:56 +0200 Subject: [PATCH 1/5] removes empty % sign when there are no votes --- app/helpers/application_helper.rb | 4 ++++ app/models/debate.rb | 6 ------ app/views/debates/show.html.erb | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e3f79f023..32cb386c8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,4 +4,8 @@ module ApplicationHelper debate.tag_list.map { |tag| link_to sanitize(tag), debates_path(tag: tag) }.join(', ').html_safe end + def percentage(vote, debate) + return if debate.total_votes == 0 + debate.send(vote).percent_of(debate.total_votes).to_s + "%" + end end diff --git a/app/models/debate.rb b/app/models/debate.rb index 0bebf6b8e..01dfa07c3 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -12,12 +12,6 @@ class Debate < ActiveRecord::Base 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 get_likes.size end diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 5efdd833a..84226d926 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -10,12 +10,12 @@
<%= link_to "up", debate_votes_path(@debate, value: 'yes'), method: "post" %> - <%= @debate.percentage('likes') %>% + <%= percentage('likes', @debate) %>
<%= link_to "down", debate_votes_path(@debate, value: 'no'), method: "post" %> - <%= @debate.percentage('dislikes') %>% + <%= percentage('dislikes', @debate) %>
Votos <%= @debate.total_votes %> From 2bd2ceaf592eea5ea1608ff7688904cedf5935da Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 18 Jul 2015 21:28:38 +0200 Subject: [PATCH 2/5] makes debates/index the root url --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index a527a7ad5..f60f0922b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ Rails.application.routes.draw do # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" - root 'welcome#index' + root 'debates#index' resources :debates do resources :votes, only: :create resources :comments, only: :create From 580eda96216c3a20675073701dd30b8e3976fd62 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 18 Jul 2015 21:29:39 +0200 Subject: [PATCH 3/5] adds minimum decency styling --- app/views/debates/show.html.erb | 20 +++++++++++--------- app/views/devise/menu/_login_items.html.erb | 20 +++++++++++--------- app/views/layouts/application.html.erb | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 84226d926..af8f60720 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -1,13 +1,13 @@ -
+

<%= @debate.title %>

<%= @debate.description %>

Creado el: <%= l @debate.created_at.to_date %> por: <%= @debate.author.name %>

-
+ -
+
<%= link_to "up", debate_votes_path(@debate, value: 'yes'), method: "post" %> <%= percentage('likes', @debate) %> @@ -19,20 +19,22 @@
Votos <%= @debate.total_votes %> +
+ +
+ <%= render 'shared/tags', debate: @debate %>


-<%= render 'shared/tags', debate: @debate %> - -

-Deja tu comentario -<%= render 'comments/form', parent: @debate %> -

Comentarios

<%= render @debate.root_comments %>
+Deja tu comentario +<%= render 'comments/form', parent: @debate %> + +

<%= link_to 'Edit', edit_debate_path(@debate) %> | <%= link_to 'Back', debates_path %> \ No newline at end of file diff --git a/app/views/devise/menu/_login_items.html.erb b/app/views/devise/menu/_login_items.html.erb index 89b9ad253..8b20efedd 100644 --- a/app/views/devise/menu/_login_items.html.erb +++ b/app/views/devise/menu/_login_items.html.erb @@ -1,9 +1,11 @@ -<% if user_signed_in? %> -
  • - <%= link_to('Logout', destroy_user_session_path, :method => :delete) %> -
  • -<% else %> -
  • - <%= link_to('Login', new_user_session_path) %> -
  • -<% end %> \ No newline at end of file +
    + <% if user_signed_in? %> +
  • + <%= link_to('Logout', destroy_user_session_path, :method => :delete) %> +
  • + <% else %> +
  • + <%= link_to('Login', new_user_session_path) %> +
  • + <% end %> +
    \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bb1a5c28f..85f4e3838 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,7 +11,7 @@ <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> - +

    <%= notice %>

    <%= alert %>

    From 2eb06020970acf40dc95ed8aa9f84871bef4f2dd Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 18 Jul 2015 21:37:15 +0200 Subject: [PATCH 4/5] fixes specs --- spec/features/home_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index 0fa8b3255..5812ebb9d 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -4,7 +4,7 @@ feature "Home" do scenario "Welcome message" do visit '/' - expect(page).to have_content 'Bienvenido al Ayuntamiento de Madrid' + expect(page).to have_content 'Debates sobre Madrid' end end From 9cd3d77536f576d0e43c634cf840e4eaada19399 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 18 Jul 2015 21:38:13 +0200 Subject: [PATCH 5/5] removes placeholder home --- app/controllers/welcome_controller.rb | 6 ------ app/views/welcome/index.html.erb | 1 - 2 files changed, 7 deletions(-) delete mode 100644 app/controllers/welcome_controller.rb delete mode 100644 app/views/welcome/index.html.erb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb deleted file mode 100644 index dd09ea984..000000000 --- a/app/controllers/welcome_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class WelcomeController < ApplicationController - - def index - end - -end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb deleted file mode 100644 index c71238c69..000000000 --- a/app/views/welcome/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -

    Bienvenido al Ayuntamiento de Madrid