Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: scryptmouse/activeadmin-sortable-tree
base: 760020e041
...
head fork: scryptmouse/activeadmin-sortable-tree
compare: 05296abc1b
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/active_admin/sortable/controller_actions.rb
View
12 lib/active_admin/sortable/controller_actions.rb
@@ -12,6 +12,7 @@ def sortable(options = {})
:max_levels => 0,
:protect_root => false,
:collapsible => false, #hides +/- buttons
+ :sti => false, # Using single-table inheritance?
:start_collapsed => false
# BAD BAD BAD FIXME: don't pollute original class
@@ -23,22 +24,29 @@ def sortable(options = {})
collection_action :sort, :method => :post do
resource_name = active_admin_config.resource_name.to_s.underscore.parameterize('_')
+ sortable_klass = options[:sti] ? resource_class.base_class : resource_class
+
records = params[resource_name].inject({}) do |res, (resource, parent_resource)|
- res[resource_class.find(resource)] = resource_class.find(parent_resource) rescue nil
+ res[sortable_klass.find(resource)] = sortable_klass.find(parent_resource) rescue nil
res
end
+
errors = []
+
ActiveRecord::Base.transaction do
records.each_with_index do |(record, parent_record), position|
record.send "#{options[:sorting_attribute]}=", position
+
if options[:tree]
record.send "#{options[:parent_method]}=", parent_record
end
+
errors << {record.id => record.errors} if !record.save
end
end
+
if errors.empty?
- head 200
+ head 204
else
render json: errors, status: 422
end

No commit comments for this range

Something went wrong with that request. Please try again.