Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions app/controllers/votes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class VotesController < ApplicationController
before_action :require_voting_open
before_action :require_authentication
before_action :set_submission

Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@
</div>

<div>
<% 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 %>
Expand Down
Loading