aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/admin_public_body_heading_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/admin_public_body_heading_controller.rb')
-rw-r--r--app/controllers/admin_public_body_heading_controller.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/controllers/admin_public_body_heading_controller.rb b/app/controllers/admin_public_body_heading_controller.rb
index 43d8e329c..cc9d586a7 100644
--- a/app/controllers/admin_public_body_heading_controller.rb
+++ b/app/controllers/admin_public_body_heading_controller.rb
@@ -18,6 +18,27 @@ class AdminPublicBodyHeadingController < AdminController
end
end
+ def reorder
+ error = nil
+ ActiveRecord::Base.transaction do
+ params[:headings].each_with_index do |heading_id, index|
+ begin
+ heading = PublicBodyHeading.find(heading_id)
+ rescue ActiveRecord::RecordNotFound => e
+ error = e.message
+ raise ActiveRecord::Rollback
+ end
+ heading.display_order = index
+ unless heading.save
+ error = heading.errors.full_messages.join(",")
+ raise ActiveRecord::Rollback
+ end
+ end
+ render :nothing => true, :status => :ok and return
+ end
+ render :text => error, :status => :unprocessable_entity
+ end
+
def new
@heading = PublicBodyHeading.new
render :formats => [:html]