From 97aecb984afa6a7d8d1424f544b8e32d8c87603d Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 9 Aug 2009 14:45:12 +0200 Subject: added sorting (via drag and drop) and deleting of menu items. Its not perfect though and needs more styling. I'm unsure about the proper route for the sort action. Will investigate. --- app/controllers/menu_items_controller.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app/controllers/menu_items_controller.rb') diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb index 7b71693..dac78d9 100644 --- a/app/controllers/menu_items_controller.rb +++ b/app/controllers/menu_items_controller.rb @@ -3,7 +3,7 @@ class MenuItemsController < ApplicationController layout 'admin' def index - @menu_items = MenuItem.all + @menu_items = MenuItem.all(:order => "position ASC") end def show @@ -35,7 +35,19 @@ class MenuItemsController < ApplicationController end end - def delete + def destroy + menu_item = MenuItem.find( params[:id] ) + menu_item.destroy + redirect_to menu_items_path + end + + def sort + params[:menu_items].each_with_index do |item_id, index| + menu_item = MenuItem.find(item_id) + menu_item.update_attributes(:position => index + 1) + end + + render :nothing => true end end -- cgit v1.3