From fad1ade73c837f00e6e2b8e9f1bbf70346cebfcf Mon Sep 17 00:00:00 2001 From: Jeremy Smith Date: Tue, 31 Mar 2026 10:21:18 -0400 Subject: [PATCH] Close voting --- app/controllers/application_controller.rb | 5 +++++ app/controllers/votes_controller.rb | 5 +++++ app/views/pages/home.html.erb | 18 ++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0dea441..1d63cb1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,4 +24,9 @@ def submissions_open? Time.current < submission_deadline end helper_method :submissions_open? + + def voting_open? + false + end + helper_method :voting_open? end diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index b713001..39d7d18 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -1,4 +1,5 @@ class VotesController < ApplicationController + before_action :require_voting_open before_action :require_authentication before_action :set_submission @@ -20,6 +21,10 @@ def destroy private + def require_voting_open + redirect_to root_path, alert: "Voting is closed." unless voting_open? + end + def set_submission @submission = Submission.find(params[:submission_id]) end diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index d0de4d0..3030ef7 100644 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -63,14 +63,16 @@
- <% if Current.user && submission.user_id != Current.user.id %> - <% if @voted_submission_ids.include?(submission.id) %> - <%= button_to submission_vote_path(submission), method: :delete, class: "inline-flex items-center gap-1 text-sm px-3 py-1 rounded-full cursor-pointer bg-gray-400 bg-linear-to-t from-gray-500 to-gray-400 text-white" do %> - Clear Vote - <% end %> - <% else %> - <%= button_to submission_vote_path(submission), method: :post, class: "inline-flex items-center gap-1 text-sm px-3 py-1 rounded-full cursor-pointer bg-[#C41C1C] bg-linear-to-t from-[#C41C1C] to-[#DD423E] text-white" do %> - ⬆ Vote + <% if voting_open? %> + <% if Current.user && submission.user_id != Current.user.id %> + <% if @voted_submission_ids.include?(submission.id) %> + <%= button_to submission_vote_path(submission), method: :delete, class: "inline-flex items-center gap-1 text-sm px-3 py-1 rounded-full cursor-pointer bg-gray-400 bg-linear-to-t from-gray-500 to-gray-400 text-white" do %> + Clear Vote + <% end %> + <% else %> + <%= button_to submission_vote_path(submission), method: :post, class: "inline-flex items-center gap-1 text-sm px-3 py-1 rounded-full cursor-pointer bg-[#C41C1C] bg-linear-to-t from-[#C41C1C] to-[#DD423E] text-white" do %> + ⬆ Vote + <% end %> <% end %> <% end %> <% end %>