Allow deleting candidates
This commit is contained in:
parent
15daf75c38
commit
4462159b93
2 changed files with 13 additions and 1 deletions
11
vote.rb
11
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])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue