-
Notifications
You must be signed in to change notification settings - Fork 344
/
locations_controller.rb
82 lines (67 loc) · 2.2 KB
/
locations_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Admin
class LocationsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def index
@locations = Kaminari.paginate_array(policy_scope(Location)).
page(params[:page]).per(params[:per_page])
end
def edit
@location = Location.find(params[:id])
@org = @location.organization
authorize @location
end
def update
@location = Location.find(params[:id])
@org = @location.organization
authorize @location
if @location.update(location_params)
redirect_to [:admin, @location],
notice: 'Location was successfully updated.'
else
render :edit
end
end
def new
@location = Location.new
authorize @location
end
def create
@location = Location.new(location_params)
org = @location.organization
authorize org if org.present?
if @location.save
redirect_to [:admin, @location], notice: 'Location was successfully created.'
else
render :new
end
end
def destroy
location = Location.find(params[:id])
authorize location
location.destroy
redirect_to admin_locations_path
end
private
# rubocop:disable MethodLength
def location_params
params.require(:location).permit(
:organization_id, { accessibility: [] }, :active, { admin_emails: [] },
:alternate_name, :description, :email, { languages: [] }, :latitude,
:longitude, :name, :short_desc, :transportation, :website, :virtual,
address_attributes: %i[
address_1 address_2 city state_province postal_code country id _destroy
],
mail_address_attributes: %i[
attention address_1 address_2 city state_province postal_code country id _destroy
],
phones_attributes: %i[
country_prefix department extension number number_type vanity_number id _destroy
],
regular_schedules_attributes: %i[weekday opens_at closes_at id _destroy],
holiday_schedules_attributes: %i[closed start_date end_date opens_at closes_at id _destroy]
)
end
# rubocop:enable MethodLength
end
end