1
試圖將嵌套可排序到我的Rails應用程序。 我正在使用Mongoid和Ancestry gem,並且我正在嘗試使用Nested-Sortable進行拖放時更新parent_id
類別的頁面。使用NestedSortable與Ancestry gem和Mongoid
一直在嘗試做實驗,但並沒有真正理解NestedSortable吐出來創建一個將讀取它的控制器。
我的控制器有:
def sort
Category.update_all({parent_id: params[:parent_id].to_i})
render nothing: true
end
路線:
resources :symbols, :as => :categories, :controller => :categories do
collection {post :sort}
end
Reorder.js.coffee:
jQuery ->
$('.reorder-tree').nestedSortable
handle: '.handle'
items: 'li'
toleranceElement: '> div'
update: ->
$.post($(this).data('update-url'), $(this).nestedSortable('serialize'))
我的訂貨觀點吐出東西這樣的:
<ol class=reorder-tree>
<li id="category_513d372b10188f9b6b000014"><div>
<i class="icon-move handle"></i>
<a href="/symbols/chickne">Chickne</a>
<span class="btn-group show-on-hover">
<a href="/symbols/new?parent_id=chickne" class="btn btn-micro" data-remote="true" title="Add Sub-Category"><i class="icon-plus"></i>
</a>
<a href="/symbols/chickne/edit" class="btn btn-micro"><i class="icon-pencil"></i>
</a>
<a href="/symbols/chickne" class="btn btn-micro" data-method="delete" data-remote="true" rel="nofollow" title="Delete Category"><i class="icon-remove"></i>
</a>
</span>
</div>
<ol class="visible"><li id="category_513d373310188f9b6b000016"><div>
<i class="icon-move handle"></i>
<a href="/symbols/smoking-babies">Smoking Babies</a>
<span class="btn-group show-on-hover">
<a href="/symbols/new?parent_id=smoking-babies" class="btn btn-micro" data-remote="true" title="Add Sub-Category"><i class="icon-plus"></i>
</a>
<a href="/symbols/smoking-babies/edit" class="btn btn-micro"><i class="icon-pencil"></i>
</a>
<a href="/symbols/smoking-babies" class="btn btn-micro" data-method="delete" data-remote="true" rel="nofollow" title="Delete Category"><i class="icon-remove"></i>
</a>
</span>
</div>
<ol class="hide"></ol>
</li>
</ol></li>
</ol>
任何幫助,將不勝感激,謝謝。