Class: Admin::BranchesController
Overview
typed: ignore frozen_string_literal: true
Constant Summary
Admin::BaseController::INTERNAL_SERVER_ERROR_MESSAGE
Instance Method Summary
collapse
#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session
#append_info_to_payload
#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?
#setup_locale
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Method Details
#create ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/admin/branches_controller.rb', line 20
def create
branch_params = params.require(:branch).permit(:name, :logo)
@branch = Branch.new branch_params
if @branch.valid? && @branch.save
redirect_to [:admin, @branch], notice: 'Branch created successfully'
else
render :new, alert: @branch.errors.full_messages.to_sentence
end
end
|
#destroy ⇒ Object
53
54
55
56
57
58
59
|
# File 'app/controllers/admin/branches_controller.rb', line 53
def destroy
if params.key?(:restaurant_id)
destroy_restaurant
else
destroy_branch
end
end
|
#edit ⇒ Object
35
|
# File 'app/controllers/admin/branches_controller.rb', line 35
def edit; end
|
#index ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'app/controllers/admin/branches_controller.rb', line 7
def index
set_meta_tags title: 'Restaurant Branches Overview'
@grid = ::Admin::BranchesGrid.new(params[:admin_branches_grid]) do |scope|
scope.page(params[:page]).per(50)
end
etag = CityHash.hash32([self.class.to_s, @grid.assets.cache_key, params])
return unless stale?(etag: etag)
end
|
#new ⇒ Object
16
17
18
|
# File 'app/controllers/admin/branches_controller.rb', line 16
def new
@branch = Branch.new
end
|
#show ⇒ Object
31
32
33
|
# File 'app/controllers/admin/branches_controller.rb', line 31
def show
set_meta_tags title: "#{@branch.name} Branch"
end
|
#update ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/controllers/admin/branches_controller.rb', line 37
def update
branch_param = params.require(:branch).permit(:name, :restaurants, :logo)
if branch_param.key?(:restaurants)
restaurant = Restaurant.find(branch_param.require(:restaurants))
if restaurant.update branch_id: @branch.id
redirect_back fallback_location: back_fallback_location, notice: "#{restaurant.name} restaurant added successfully"
else
redirect_back fallback_location: back_fallback_location, alert: "#{restaurant.name} restaurant could not be added. #{restaurant.errors.full_messages.to_sentence}"
end
elsif @branch.update branch_param
redirect_to [:admin, @branch], notice: 'Branch successfully updated'
else
render :edit
end
end
|