Class: Admin::CitiesController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/cities_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::INTERNAL_SERVER_ERROR_MESSAGE

Instance Method Summary collapse

Methods inherited from BaseController

#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from AdminHelper

#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?

Methods included from UpdateLocaleConcern

#setup_locale

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/admin/cities_controller.rb', line 21

def create
  @city = City.new(city_params)
  @countries = Country.find_each.map do |country|
    ["#{country.name} (#{country.id})", country.id]
  end

  if @city.save
    redirect_to admin_cities_path, notice: 'City was successfully created.'
  else
    render :new, alert: @city.errors.full_messages.to_sentence
  end
end

#editObject



34
35
36
# File 'app/controllers/admin/cities_controller.rb', line 34

def edit
  @city.restaurants.build
end

#indexObject



8
9
10
11
12
# File 'app/controllers/admin/cities_controller.rb', line 8

def index
  @grid = Admin::Cities::CitiesGrid.new(params[:admin_cities_cities_grid]) do |scope|
    scope.page(params[:page])
  end
end

#newObject



14
15
16
17
18
19
# File 'app/controllers/admin/cities_controller.rb', line 14

def new
  @city = City.new
  @countries = Country.find_each.map do |country|
    ["#{country.name} (#{country.id})", country.id]
  end
end

#showObject



48
49
50
51
52
# File 'app/controllers/admin/cities_controller.rb', line 48

def show
  @grid = Admin::Cities::RestaurantsGrid.new(params[:admin_cities_restaurants_grid]) do
    @city.restaurants.page(params[:page])
  end
end

#updateObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/admin/cities_controller.rb', line 38

def update
  permitted_params = params.require(:city).permit(:name, *City.globalize_attribute_names, :icon, :is_mini_homepage, :display_order,
                                                  :new_city, city_delivery_citys_attributes: [:id, :priority, :delivery_city_id, :_destroy], country_attributes: [:id, :icon, :_destroy])
  if @city.update(permitted_params)
    redirect_to admin_cities_path, notice: 'City updated successfully'
  else
    render :edit, alert: @city.errors.full_messages.to_sentence
  end
end