diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-09-19 09:22:35 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-22 12:42:08 +0100 |
commit | ffb60e1a6cbd35c8cae4902bb28d7ba4f32ed740 (patch) | |
tree | aec571c88d7001b83745f10ece089f12ee1f8e13 /app/controllers/admin_public_body_heading_controller.rb | |
parent | 897177e0660a3d567fcb4c4d203c1f7da8b5b0a4 (diff) |
Add actions for reordering public body headings and categories.
Diffstat (limited to 'app/controllers/admin_public_body_heading_controller.rb')
-rw-r--r-- | app/controllers/admin_public_body_heading_controller.rb | 21 |
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] |