Index: test/fixtures/packages.yml =================================================================== --- test/fixtures/packages.yml (revision 9) +++ test/fixtures/packages.yml (working copy) @@ -3,7 +3,9 @@ id: 1 user_id: 1000001 name: package1 + images: /images another: id: 2 user_id: 1000001 name: package2 + images: /images Index: app/controllers/home_controller.rb =================================================================== --- app/controllers/home_controller.rb (revision 9) +++ app/controllers/home_controller.rb (working copy) @@ -52,4 +52,38 @@ @result = @player.result @session[:back_to] = {:controller => controller_name, :action => action_name} end + + def swap + drag_dom_id = params[:id] + drop_dom_id = params[:recv_id] + + /drag_(\d+)/ =~ drag_dom_id + drag_position = $1.to_i+1 + /drop_(\d+)/ =~ drop_dom_id + drop_position = $1.to_i+1 + + drag_card = nil + drop_card = nil + Card.with_scope(mine) { + drag_card = Card.find_by_position(drag_position) + drop_card = Card.find_by_position(drop_position) + } + + if drag_card && drop_card + # swap position + orig_drag_card_position = drag_card.position + drag_card.position = drop_card.position + drop_card.position = orig_drag_card_position + + drag_card.save! + drop_card.save! + elsif drag_card + drag_card.move_to_bottom + end + + @cards = cards + render :update do |page| + page.replace_html 'pockets', :partial => 'pockets' + end + end end Index: app/views/home/_pockets.rhtml =================================================================== --- app/views/home/_pockets.rhtml (revision 9) +++ app/views/home/_pockets.rhtml (working copy) @@ -32,13 +32,33 @@ <% end %> -