Class: SortableController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SortableController
- Defined in:
- app/controllers/sortable_controller.rb
Constant Summary collapse
- VERIFIER =
Rails.application.(:rails_sortable_generate_sortable_id)
Instance Method Summary collapse
-
#reorder ⇒ Object
post /sortable/reorder, rails_sortable: [ “BAhJIhVjbGFzcz1JdGVtLGlkPTUwBjoGRVQ=–b48adfad6d6d7764e4106c44fc090fcad15d721e”, “BAhJIhVjbGFzcz1JdGVtLGlkPTQxBjoGRVQ=–ac1c2d3b8eae8dd72e49fae302005e5ae4fc00a4”, …] Param ‘rails_sorable` is an array object containing encoded tokens, and each token must be able to be decoded with VERIFIER to a string formatted as “class=CLASS_NAME,id=ID”.
Instance Method Details
#reorder ⇒ Object
post /sortable/reorder, rails_sortable: [
"BAhJIhVjbGFzcz1JdGVtLGlkPTUwBjoGRVQ=--b48adfad6d6d7764e4106c44fc090fcad15d721e",
"BAhJIhVjbGFzcz1JdGVtLGlkPTQxBjoGRVQ=--ac1c2d3b8eae8dd72e49fae302005e5ae4fc00a4", ...]
Param ‘rails_sorable` is an array object containing encoded tokens, and each token must be able to be decoded with VERIFIER to a string formatted as “class=CLASS_NAME,id=ID”.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/sortable_controller.rb', line 12 def reorder ActiveRecord::Base.transaction do params['rails_sortable'].each_with_index do |token, new_sort| model = find_model(token) current_sort = model.read_attribute(model.class.sort_attribute) model.update_sort!(new_sort) if current_sort != new_sort end end head :ok end |