From 43cf6b70b74f4bbb6335236c9a37de5af667c5bc Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 4 Oct 2013 15:07:24 +0800 Subject: [PATCH] Fix structure reorder position --- app/controllers/admin/items_controller.rb | 2 +- app/models/item.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index e5a2c2be..183141e1 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -27,7 +27,7 @@ class Admin::ItemsController < OrbitBackendController def update_position item = Item.find(params[:id]) - item.shift_to(params[:parent_id], params[:position]) + item.shift_to(params[:parent_id], params[:position].to_i - 1) render :nothing => true end diff --git a/app/models/item.rb b/app/models/item.rb index 7cb5b61e..f06109a5 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -45,9 +45,10 @@ class Item end def shift_to(new_parent, position) - unless self.parent_id.to_s.eql?(new_parent) && self.position.eql?(position.to_i) + position = position.to_i + unless self.parent_id.to_s.eql?(new_parent) && self.position == position new_parent = Item.find(new_parent) - current_position_sibling = find_by_parent_and_position(new_parent, position.to_i) + current_position_sibling = find_by_parent_and_position(new_parent, position) if current_position_sibling move_above(current_position_sibling) elsif self.parent != new_parent