Class: Admin::MenuItemsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::MenuItemsController
- Defined in:
- app/controllers/admin/menu_items_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
- #update_sort ⇒ Object
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/admin/menu_items_controller.rb', line 19 def create 'New', :new_admin_page_path @menu_item = SpudMenuItem.new() @menu_item. = @menu.id if params[:spud_menu_item][:parent_id].blank? @menu_item.parent_id = @menu.id @menu_item.parent_type = 'SpudMenu' else @menu_item.parent_type = 'SpudMenuItem' end if @menu_item.name.blank? && !@menu_item.spud_page.blank? @menu_item.name = @menu_item.spud_page.name end if @menu_item..blank? highest_sibling = @menu_item.parent..order('menu_order desc').first unless highest_sibling.blank? @menu_item. = highest_sibling. + 1 end end flash[:notice] = 'Menu Created successfully!' if @menu_item.save respond_with @menu_item, location: end |
#destroy ⇒ Object
64 65 66 67 68 |
# File 'app/controllers/admin/menu_items_controller.rb', line 64 def destroy flash[:notice] = 'Menu Item removed!' if @menu_item.destroy respond_with @menu_item, location: end |
#edit ⇒ Object
43 44 45 46 47 |
# File 'app/controllers/admin/menu_items_controller.rb', line 43 def edit "Edit #{@menu_item.name}", :edit_admin_menu_menu_item_path @menu_item.parent_id = nil if @menu_item.parent_type == 'SpudMenu' respond_with @menu_item end |
#index ⇒ Object
7 8 9 10 |
# File 'app/controllers/admin/menu_items_controller.rb', line 7 def index @menu_items = @menu..order(:menu_order).includes(:spud_menu_items) respond_with @menu_items end |
#new ⇒ Object
12 13 14 15 16 17 |
# File 'app/controllers/admin/menu_items_controller.rb', line 12 def new 'New', :new_admin_page_path @menu_item = @menu..new respond_with @menu_item end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/admin/menu_items_controller.rb', line 49 def update "Edit #{@menu_item.name}", :edit_admin_menu_menu_item_path if params[:spud_menu_item][:parent_id].blank? params[:spud_menu_item][:parent_type] = 'SpudMenu' params[:spud_menu_item][:parent_id] = @menu.id else params[:spud_menu_item][:parent_type] = 'SpudMenuItem' end @menu_item.attributes = () @menu_item. = @menu.id flash[:notice] = 'Menu saved successfully!' if @menu_item.save respond_with @menu_item, location: end |
#update_sort ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/admin/menu_items_controller.rb', line 70 def update_sort params[:order]&.each_with_index do |item, index| val = item.to_i = @menu..find_by(id: val) . = index .save end respond_to do |format| format.json { head :no_content } end end |