Class: Admin::MenusController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Admin::MenusController
- Defined in:
- app/controllers/admin/menus_controller.rb
Overview
Responsible to manage package's menus
Constant Summary
Constants inherited from BaseController
BaseController::INTERNAL_SERVER_ERROR_MESSAGE
Instance Attribute Summary collapse
-
#add_on ⇒ Object
readonly
Returns the value of attribute add_on.
Instance Method Summary collapse
Methods inherited from BaseController
#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session
Methods included from LogrageCustomLogger
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
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 Attribute Details
#add_on ⇒ Object (readonly)
Returns the value of attribute add_on.
10 11 12 |
# File 'app/controllers/admin/menus_controller.rb', line 10 def add_on @add_on end |
Instance Method Details
#create ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/admin/menus_controller.rb', line 33 def create permitted_params = params.require(:add_ons_menu).permit(:add_on_id, :add_on_type, image: []) payloads = permitted_params.fetch(:image, []).map do |p| { add_on_id: permitted_params[:add_on_id], add_on_type: permitted_params[:add_on_type], image: p, } end operation = AddOns::Menu.create payloads if operation.first&.id&.present? flash[:notice] = 'Success' else flash[:alert] = operation.first&.errors&.&.to_sentence || INTERNAL_SERVER_ERROR_MESSAGE end redirect_back fallback_location: back_fallback_location end |
#destroy ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin/menus_controller.rb', line 60 def destroy if params[:id] == 'all' add_on..destroy_all else = AddOns::Menu.find_by(id: params.require(:id)) if .blank? return render json: { message: 'Menu not found' }, status: :not_found end if .destroy render json: { message: 'Menu deleted successfully' } else render json: { message: .errors..to_sentence }, status: :unprocessable_entity end end end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/admin/menus_controller.rb', line 12 def index respond_to do |format| format.html do @add_on_menu = add_on..build end format.json do render json: add_on..order_by_rank end end end |
#update ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/controllers/admin/menus_controller.rb', line 52 def update if .update params.require(:add_on_menu).permit(:index_number) render json: else render json: { message: .errors..to_sentence }, status: :unprocessable_entity end end |
#update_image ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/admin/menus_controller.rb', line 23 def update_image operation = AddOns::Menu.find(params.require(:menu_id)) operation.image = params.require(:file) if operation.valid? && operation.save render json: { success: true } else render json: { success: false, message: operation.errors..to_sentence } end end |