From 4462159b934fece2011e7d9cd59b12d2fd5a2ba8 Mon Sep 17 00:00:00 2001 From: ricola Date: Sun, 6 Apr 2025 17:04:31 -0600 Subject: [PATCH] Allow deleting candidates --- views/votes_edit.erb | 3 +++ vote.rb | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/views/votes_edit.erb b/views/votes_edit.erb index a54407c..a9414f1 100644 --- a/views/votes_edit.erb +++ b/views/votes_edit.erb @@ -17,6 +17,9 @@ <% @vote.candidates.each do |candidate| %>

<%= candidate.name %>

<%= candidate.description %>

+
+ +
<% end %>

Add candidate

diff --git a/vote.rb b/vote.rb index 85f8fa4..994e283 100644 --- a/vote.rb +++ b/vote.rb @@ -15,7 +15,7 @@ end class Candidate < ActiveRecord::Base belongs_to :vote - has_many :ratings + has_many :ratings, dependent: :destroy def mj return MajorityJudgment.new(self.ratings.collect {|r| r.value }) @@ -151,6 +151,15 @@ post '/votes/:id/candidates' do redirect '/votes/' + @vote.secure_id end +post '/votes/:id/candidates/:cid/delete' do + redirect '/login' unless current_user + @vote = Vote.find_by(secure_id: params[:id]) + redirect '/votes/' + @vote.secure_id unless @vote.state == "draft" and @vote.users.exists?(current_user.id) + @candidate = Candidate.find(params[:cid]) + @candidate.destroy + redirect '/votes/' + @vote.secure_id +end + post '/votes/:id/open' do redirect '/login' unless current_user @vote = Vote.find_by(secure_id: params[:id])