Validate candidate name
This commit is contained in:
parent
f8b5f80823
commit
b2e76f4363
3 changed files with 49 additions and 14 deletions
40
vedia.rb
40
vedia.rb
|
|
@ -346,11 +346,20 @@ post '/votes/:id/candidates' do
|
|||
find_vote
|
||||
require_organizer
|
||||
require_draft_vote
|
||||
@candidate = Candidate.new(name: params[:name],
|
||||
description: params[:description])
|
||||
@candidate.vote = @vote
|
||||
@candidate.save
|
||||
redirect '/votes/' + @vote.secure_id
|
||||
@errors = []
|
||||
if params[:name].empty?
|
||||
@errors << OpenStruct.new(:attribute => :name, :type => :blank)
|
||||
end
|
||||
if not @errors.empty?
|
||||
@params = params
|
||||
erb :votes_edit
|
||||
else
|
||||
@candidate = Candidate.new(name: params[:name],
|
||||
description: params[:description])
|
||||
@candidate.vote = @vote
|
||||
@candidate.save
|
||||
redirect '/votes/' + @vote.secure_id
|
||||
end
|
||||
end
|
||||
|
||||
get '/votes/:id/candidates/:cid' do
|
||||
|
|
@ -360,6 +369,8 @@ get '/votes/:id/candidates/:cid' do
|
|||
require_draft_vote
|
||||
find_candidate
|
||||
require_candidate_in_vote
|
||||
params[:name] = @candidate.name
|
||||
params[:description] = @candidate.description
|
||||
erb :candidates_edit
|
||||
end
|
||||
|
||||
|
|
@ -370,11 +381,20 @@ post '/votes/:id/candidates/:cid' do
|
|||
require_draft_vote
|
||||
find_candidate
|
||||
require_candidate_in_vote
|
||||
@candidate.name = params[:name]
|
||||
@candidate.description = params[:description]
|
||||
@candidate.save
|
||||
redirect '/votes/' + @vote.secure_id
|
||||
erb :candidates_edit
|
||||
@errors = []
|
||||
if params[:name].empty?
|
||||
@errors << OpenStruct.new(:attribute => :name, :type => :blank)
|
||||
end
|
||||
if not @errors.empty?
|
||||
@params = params
|
||||
erb :candidates_edit
|
||||
else
|
||||
@candidate.name = params[:name]
|
||||
@candidate.description = params[:description]
|
||||
@candidate.save
|
||||
redirect '/votes/' + @vote.secure_id
|
||||
erb :candidates_edit
|
||||
end
|
||||
end
|
||||
|
||||
post '/votes/:id/candidates/:cid/delete' do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue