Ответ 1
Я применил это недавно, используя столбец с именем position на моей модели HomeSlide.
ActiveAdmin.register HomeSlide do
config.sort_order = 'position_asc'
index do
column :title
default_actions
end
# This action is called by javascript when you drag and drop a column
# It iterates through the collection and sets the new position based on the
# order that jQuery submitted them
collection_action :sort, :method => :post do
params[:home_slide].each_with_index do |id, index|
HomeSlide.update_all(['position=?', index+1], ['id=?', id])
end
render :nothing => true
end
end
Добавьте это в свой active_admin javascripts (скрипт кофе)
sendSortRequestOfModel = (model_name) ->
formData = $('#' + model_name + ' tbody').sortable('serialize')
formData += "&" + $('meta[name=csrf-param]').attr("content") + "=" + encodeURIComponent($('meta[name=csrf-token]').attr("content"))
$.ajax
type: 'post'
data: formData
dataType: 'script'
url: '/admin/' + model_name + '/sort'
jQuery ($) ->
# home page slides
if $('body.admin_home_slides.index').length
$( "#home_slides tbody" ).disableSelection()
$( "#home_slides tbody" ).sortable
axis: 'y'
cursor: 'move'
update: (event, ui) ->
sendSortRequestOfModel("home_slides")