Skip to content

Commit 038a8fb

Browse files
Close voting (#11)
1 parent bb127f4 commit 038a8fb

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ def submissions_open?
2424
Time.current < submission_deadline
2525
end
2626
helper_method :submissions_open?
27+
28+
def voting_open?
29+
false
30+
end
31+
helper_method :voting_open?
2732
end

app/controllers/votes_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class VotesController < ApplicationController
2+
before_action :require_voting_open
23
before_action :require_authentication
34
before_action :set_submission
45

@@ -20,6 +21,10 @@ def destroy
2021

2122
private
2223

24+
def require_voting_open
25+
redirect_to root_path, alert: "Voting is closed." unless voting_open?
26+
end
27+
2328
def set_submission
2429
@submission = Submission.find(params[:submission_id])
2530
end

app/views/pages/home.html.erb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@
6363
</div>
6464

6565
<div>
66-
<% if Current.user && submission.user_id != Current.user.id %>
67-
<% if @voted_submission_ids.include?(submission.id) %>
68-
<%= 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 %>
69-
Clear Vote
70-
<% end %>
71-
<% else %>
72-
<%= 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 %>
73-
⬆ Vote
66+
<% if voting_open? %>
67+
<% if Current.user && submission.user_id != Current.user.id %>
68+
<% if @voted_submission_ids.include?(submission.id) %>
69+
<%= 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 %>
70+
Clear Vote
71+
<% end %>
72+
<% else %>
73+
<%= 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 %>
74+
⬆ Vote
75+
<% end %>
7476
<% end %>
7577
<% end %>
7678
<% end %>

0 commit comments

Comments
 (0)