Validate vote title
This commit is contained in:
parent
4ad1c4cb86
commit
78abcce758
3 changed files with 44 additions and 10 deletions
18
vedia.rb
18
vedia.rb
|
|
@ -277,12 +277,21 @@ end
|
||||||
|
|
||||||
post '/votes/new' do
|
post '/votes/new' do
|
||||||
require_login
|
require_login
|
||||||
|
@errors = []
|
||||||
|
if params[:title].empty?
|
||||||
|
@errors << OpenStruct.new(:attribute => :title, :type => :blank)
|
||||||
|
end
|
||||||
|
if not @errors.empty?
|
||||||
|
@params = params
|
||||||
|
erb :votes_new
|
||||||
|
else
|
||||||
@vote = Vote.create(secure_id: SecureRandom.hex(8),
|
@vote = Vote.create(secure_id: SecureRandom.hex(8),
|
||||||
title: params[:title],
|
title: params[:title],
|
||||||
description: params[:description],
|
description: params[:description],
|
||||||
state: 'draft')
|
state: 'draft')
|
||||||
@vote.users << current_user
|
@vote.users << current_user
|
||||||
redirect '/votes/' + @vote.secure_id
|
redirect '/votes/' + @vote.secure_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/votes/:id' do
|
get '/votes/:id' do
|
||||||
|
|
@ -315,10 +324,19 @@ post '/votes/:id/edit' do
|
||||||
find_vote
|
find_vote
|
||||||
require_organizer
|
require_organizer
|
||||||
require_draft_vote
|
require_draft_vote
|
||||||
|
@errors = []
|
||||||
|
if params[:title].empty?
|
||||||
|
@errors << OpenStruct.new(:attribute => :title, :type => :blank)
|
||||||
|
end
|
||||||
|
if not @errors.empty?
|
||||||
|
@params = params
|
||||||
|
erb :votes_edit_description
|
||||||
|
else
|
||||||
@vote.title = params[:title]
|
@vote.title = params[:title]
|
||||||
@vote.description = params[:description]
|
@vote.description = params[:description]
|
||||||
@vote.save
|
@vote.save
|
||||||
redirect '/votes/' + @vote.secure_id
|
redirect '/votes/' + @vote.secure_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/votes/:id/candidates' do
|
post '/votes/:id/candidates' do
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
<h1 class="mb-5"><%= _("Edit vote description") %></h1>
|
<h1 class="mb-5"><%= _("Edit vote description") %></h1>
|
||||||
|
|
||||||
|
<% if @errors %>
|
||||||
|
<% @errors.each do |error| %>
|
||||||
|
<% if error.attribute == :title and error.type == :blank %>
|
||||||
|
<p class="alert alert-warning mb-4"><%= _("Enter a title.") %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<form action="/votes/<%= @vote.secure_id %>/edit" method="post">
|
<form action="/votes/<%= @vote.secure_id %>/edit" method="post">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="title" class="form-label"><%= _("Title") %></label>
|
<label for="title" class="form-label"><%= _("Title") %></label>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
<h1 class="mb-5"><%= _("New vote") %></h1>
|
<h1 class="mb-5"><%= _("New vote") %></h1>
|
||||||
|
|
||||||
|
<% if @errors %>
|
||||||
|
<% @errors.each do |error| %>
|
||||||
|
<% if error.attribute == :title and error.type == :blank %>
|
||||||
|
<p class="alert alert-warning mb-4"><%= _("Enter a title.") %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<form action="/votes/new" method="post">
|
<form action="/votes/new" method="post">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="title" class="form-label"><%= _("Title") %></label>
|
<label for="title" class="form-label"><%= _("Title") %></label>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue