Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Partners being assigned Service Areas
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankocienski committed Jan 31, 2022
1 parent f4032ea commit a40fc66
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/admin/partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def create
format.html { redirect_to admin_partners_path, notice: 'Partner was successfully created.' }
format.json { render :show, status: :created, location: @partner }
else
set_neighbourhoods
format.html { render :new }
format.json { render json: @partner.errors, status: :unprocessable_entity }
end
Expand Down Expand Up @@ -107,6 +108,7 @@ def partner_params
:opening_times,
calendars_attributes: %i[id name source strategy place_id partner_id _destroy],
address_attributes: %i[street_address street_address2 street_address3 city postcode],
service_areas_attributes: %i[id neighbourhood_id],
tag_ids: [] ]

attributes << :slug if current_user.root?
Expand Down
2 changes: 2 additions & 0 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Partner < ApplicationRecord

accepts_nested_attributes_for :address, reject_if: ->(c) { c[:postcode].blank? && c[:street_address].blank? }

accepts_nested_attributes_for :service_areas

# Validations
validates :name,
presence: true,
Expand Down
2 changes: 1 addition & 1 deletion app/policies/partner_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def permitted_attributes
:opening_times,
calendars_attributes: %i[id name source strategy place_id partner_id _destroy],
address_attributes: %i[street_address street_address2 street_address3 city postcode],
service_area_attributes: %i[neighbourhood_id],
service_areas_attributes: %i[id neighbourhood_id],
tag_ids: [] ]

attrs << :slug if user.root?
Expand Down
16 changes: 16 additions & 0 deletions app/views/admin/partners/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
<br>
<hr>

<h2>Service Areas</h2>

<div class="partner__service_areas">
<% @all_neighbourhoods.each do |neighbourhood| %>
<%= fields_for "partner[service_areas_attributes][#{neighbourhood.id}]" do |sna|%>
<label>
<%= sna.check_box :neighbourhood_id, {include_hidden: false, checked: false}, neighbourhood.id %>
<%= neighbourhood.name %>
</label><br>
<% end %>
<% end %>
</div>

<br>
<hr>

<h2>Address</h2>

<div id='address'>
Expand Down

0 comments on commit a40fc66

Please sign in to comment.