From b4ef3ad3f3b4fece1b78b87c343b61ad3a740966 Mon Sep 17 00:00:00 2001 From: kellynvd Date: Fri, 20 Mar 2020 10:21:17 -0300 Subject: [PATCH] Add presence validation to address on Ngo - Remove :readonly from :address and :neighborhood Refs #146 --- app/controllers/ngo_area/ngos_controller.rb | 15 ++++++---- app/models/ngo.rb | 6 ++++ app/views/ngo_area/ngos/_form.html.erb | 31 +++++++++++++-------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/controllers/ngo_area/ngos_controller.rb b/app/controllers/ngo_area/ngos_controller.rb index 2fa10058..38037b5a 100644 --- a/app/controllers/ngo_area/ngos_controller.rb +++ b/app/controllers/ngo_area/ngos_controller.rb @@ -9,8 +9,11 @@ def new def create @ngo = Ngo.create(params_ngo) - - redirect_to ngo_area_ngos_path + if @ngo.save + redirect_to ngo_area_ngos_path + else + render :new + end end def edit @@ -19,9 +22,11 @@ def edit def update @ngo = Ngo.find(params[:id]) - @ngo.update params_ngo - - redirect_to ngo_area_ngos_path + if @ngo.update(params_ngo) + redirect_to ngo_area_ngos_path + else + render :edit + end end private diff --git a/app/models/ngo.rb b/app/models/ngo.rb index 9a7e8b83..f727b98f 100644 --- a/app/models/ngo.rb +++ b/app/models/ngo.rb @@ -8,6 +8,12 @@ class Ngo < ApplicationRecord has_one_attached :image validates :fantasy_name, presence: true + validates :zipcode, presence: true + validates :address_number, presence: true + validates :address, presence: true + validates :neighborhood, presence: true + validates :city, presence: true + validates :state, presence: true scope :active, -> { where(active: true) } diff --git a/app/views/ngo_area/ngos/_form.html.erb b/app/views/ngo_area/ngos/_form.html.erb index 7255ff6a..d98aa240 100644 --- a/app/views/ngo_area/ngos/_form.html.erb +++ b/app/views/ngo_area/ngos/_form.html.erb @@ -1,11 +1,14 @@ -
+ <%= form_error_tag(@ngo) %> + +
<%= label_tag(:social_name, 'Razão Social') %> <%= f.text_field :social_name, class: 'form-control' %>
-
+
<%= label_tag(:fantasy_name, 'Nome Fantasia') %> <%= f.text_field :fantasy_name, class: 'form-control' %> + <%= field_error_tag(@ngo, :fantasy_name) %>
<%= label_tag(:email, 'E-mail') %> @@ -63,29 +66,35 @@

Endereço

-
+
<%= label_tag(:zipcode, 'CEP') %> <%= f.number_field :zipcode, class: 'form-control' %> + <%= field_error_tag(@ngo, :zipcode) %>
-
+
<%= label_tag(:address_number, 'Número ') %> <%= f.number_field :address_number, class: 'form-control' %> + <%= field_error_tag(@ngo, :address_number) %>
-
+
<%= label_tag(:address, 'Endereço') %> - <%= f.text_field :address, class: 'form-control', :readonly => true %> + <%= f.text_field :address, class: 'form-control' %> + <%= field_error_tag(@ngo, :address) %>
-
+
<%= label_tag(:neighborhood, 'Bairro') %> - <%= f.text_field :neighborhood, class: 'form-control', :readonly => true %> + <%= f.text_field :neighborhood, class: 'form-control' %> + <%= field_error_tag(@ngo, :neighborhood) %>
-
+
<%= label_tag(:city, 'Cidade') %> <%= f.text_field :city, class: 'form-control', :readonly => true %> + <%= field_error_tag(@ngo, :city) %>
-
+
<%= label_tag(:state, 'Estado') %> <%= f.text_field :state, class: 'form-control', :readonly => true %> + <%= field_error_tag(@ngo, :state) %>

Conta bancária

@@ -116,4 +125,4 @@
-<%= javascript_include_tag "ngo_area/ngos/form" %> \ No newline at end of file +<%= javascript_include_tag "ngo_area/ngos/form" %>