Class: MenusController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- MenusController
- Defined in:
- app/controllers/menus_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #reorder ⇒ Object
- #sort ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/controllers/menus_controller.rb', line 21 def create @menu = Menu.new() if @menu.save redirect_to , notice: t('menus.create.notice') else render action: "new", warning: t('menus.create.warning'), layout: 'admin' end end |
#destroy ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/menus_controller.rb', line 39 def destroy @menu = Menu.find(params[:id]) @menu.destroy redirect_to , notice: t('menus.destroy.notice') end |
#edit ⇒ Object
16 17 18 19 |
# File 'app/controllers/menus_controller.rb', line 16 def edit @menu = Menu.find(params[:id]) switch_to_admin_layout end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/menus_controller.rb', line 6 def index @menus = Menu.ordered switch_to_admin_layout end |
#new ⇒ Object
11 12 13 14 |
# File 'app/controllers/menus_controller.rb', line 11 def new @menu = Menu.new switch_to_admin_layout end |
#reorder ⇒ Object
45 46 47 48 49 |
# File 'app/controllers/menus_controller.rb', line 45 def reorder = Menu.find(params[:id]) @menus = .self_and_siblings.ordered switch_to_admin_layout end |
#sort ⇒ Object
51 52 53 54 55 56 |
# File 'app/controllers/menus_controller.rb', line 51 def sort params[:menu].each_with_index do |id, index| Menu.update(id, position: index+1) end render nothing: true end |
#update ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/controllers/menus_controller.rb', line 30 def update @menu = Menu.find(params[:id]) if @menu.update() redirect_to , notice: t('menus.update.notice') else render action: "edit", warning: t('menus.update.warning'), layout: 'admin' end end |