From 2745f776e61e96b65715f330c688d14a0a797799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20H=C3=A1jek?= Date: Sat, 7 Oct 2023 14:22:40 +0200 Subject: [PATCH] added validation to subject and text --- .../general_agenda/application_form.rb | 12 ++++++++++-- .../general_agenda_app/general_agenda/index.html.erb | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/apps/general_agenda_app/general_agenda/application_form.rb b/app/models/apps/general_agenda_app/general_agenda/application_form.rb index fb41511e..7b25e516 100644 --- a/app/models/apps/general_agenda_app/general_agenda/application_form.rb +++ b/app/models/apps/general_agenda_app/general_agenda/application_form.rb @@ -6,8 +6,8 @@ class ApplicationForm include ActiveModel::Validations validate :recipient_present? - validates :subject, presence: true - validates :text, presence: true + validate :subject? + validate :text? attr_accessor( # Static/template attributes @@ -52,6 +52,14 @@ def valid_template? def recipient_present? errors.add(:recipient_name, 'Zvoľte prijímateľa') if recipient_name.blank? || recipient_uri.blank? end + + def subject? + errors.add(:subject, 'Predmet je povinná položka') if subject.blank? + end + + def text? + errors.add(:text, 'Text je povinná položka') if text.blank? + end end end end diff --git a/app/views/apps/general_agenda_app/general_agenda/index.html.erb b/app/views/apps/general_agenda_app/general_agenda/index.html.erb index acbeed80..758dfb3b 100644 --- a/app/views/apps/general_agenda_app/general_agenda/index.html.erb +++ b/app/views/apps/general_agenda_app/general_agenda/index.html.erb @@ -23,7 +23,7 @@
- <%= f.inputs_set :recipient_body do %> + <%= f.inputs_set :recipient_name do %>
<% end %>