1
중첩 정렬을 내 레일 앱에 통합하려고합니다. 나는 Mongoid와 Ancestry gem을 사용하고 있습니다. 그리고 Nested-Sortable로 드래그 & 드롭하는 카테고리의 parent_id
을 업데이트하는 페이지를 만들려고합니다.Ancestry gem 및 Mongoid와 함께 NestedSortable 사용
실험을 해보려고했지만 NestedSortable을 읽는 컨트롤러를 만들기 위해 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>
감사합니다. 감사드립니다. 당신은 내가 가진 후 내가 주석 것을 볼 수 있습니다
def sort
# html = "Env: #{Rails.env}. "
# infor = params[:category]
params[:category].each do |id, attr|
thisCat = params[:category][id]
@category = Category.where(:_id => id).first
# html << "ID= #{id} , thisCat= #{thisCat} Name= #{@category.name} Parent= #{@category.parent_id} ; "
unless thisCat == "null"
@category.parent_id = thisCat.to_s
@category.save
end
end
# flash[:alert] = html
# flash[:error] = infor
# render nothing: true
end
: