destructure guardian address field for appearance release

This commit is contained in:
bilal
2020-06-16 13:29:13 +02:00
parent a7b90c223b
commit 50d8ea158e
12 changed files with 108 additions and 10 deletions

View File

@@ -78,7 +78,7 @@ class AppearanceReleasesController < ApplicationController
end
def appearance_release_params
params.require(:appearance_release).permit(:contract, :guardian_address, :guardian_first_name, :guardian_last_name, :guardian_phone, :guardian_photo, :guardian_email, :minor,
params.require(:appearance_release).permit(:contract, :guardian_address_old, :guardian_first_name, :guardian_last_name, :guardian_phone, :guardian_photo, :guardian_email, :minor,
:person_address, :person_first_name, :person_last_name, :person_phone, :person_email, :person_photo,
:applicable_medium_id, :applicable_medium_text,
:territory_id, :territory_text,

View File

@@ -39,9 +39,25 @@ class Public::AppearanceReleasesController < Public::BaseController
authorize appearance_releases.build(params)
end
def guardian_params
%i[
guardian_first_name
guardian_last_name
guardian_phone
guardian_email
guardian_photo
guardian_address_street1
guardian_address_street2
guardian_address_city
guardian_address_state
guardian_address_zip
guardian_address_country
]
end
def appearance_release_params
params.require(:appearance_release).permit(:person_address, :person_first_name, :person_last_name, :person_phone, :person_email, :person_photo,
:guardian_address, :guardian_first_name, :guardian_last_name, :guardian_phone, :guardian_email, :guardian_photo, :minor,
guardian_params, :minor,
:signature_base64, :person_date_of_birth,
:locale, :contract_template,)
end

View File

@@ -16,6 +16,18 @@ class AppearanceRelease < ApplicationRecord
has_one_attached :person_photo
composed_of :guardian_address,
class_name: 'Address',
mapping: [
%w[guardian_address_street1 street1],
%w[guardian_address_street2 street2],
%w[guardian_address_city city],
%w[guardian_address_state state],
%w[guardian_address_zip zip],
%w[guardian_address_country country]
]
# These validations apply to all releases
validates :person_email, email: true, allow_blank: true
validates :person_first_name, :person_last_name, presence: true
@@ -73,6 +85,19 @@ class AppearanceRelease < ApplicationRecord
searchable_on %i[person_first_name person_last_name person_address person_email person_phone]
def guardian_address
return self.guardian_address_old if self.guardian_address_old.present?
Address.new(
self.guardian_address_street1,
self.guardian_address_street2,
self.guardian_address_city,
self.guardian_address_state,
self.guardian_address_zip,
self.guardian_address_country
).to_s(format: :full)
end
# All releases must respond to the following messages
def name
person_name

View File

@@ -23,7 +23,7 @@
<%= form.phone_field :guardian_phone, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :guardian_address, wrapper_class: "col-sm-6" %>
<%= form.text_field :guardian_address_old, wrapper_class: "col-sm-6" %>
</div>
</div>
<% end %>

View File

@@ -79,9 +79,7 @@
<div class="form-row">
<%= form.text_field :guardian_email, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :guardian_address, wrapper_class: "col-sm-6" %>
</div>
<%= render "shared/address_fields", form: form, subject: "guardian" %>
<% end %>
<hr>