Sha256: 240b9fc0c0bd888ef809fef50ab29232ecff609d27c4167c9038ccb8b3b7d01d
Contents?: true
Size: 547 Bytes
Versions: 2
Compression:
Stored size: 547 Bytes
Contents
class SortableController < ApplicationController # # post /sortable/reorder, :klass => ["1", "3", "2"] # def reorder klass, ids = parse_params models = klass.order(:sort).to_a ids.each_with_index do |id, new_sort| model = models.find {|m| m.id == id } model.update_attributes! sort: new_sort if model.sort != new_sort end render nothing: true end private def parse_params klass_name = params.keys.first ids = params[klass_name].map {|id| id.to_i } [ klass_name.constantize, ids ] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_sortable-0.0.3 | app/controllers/sortable_controller.rb |
rails_sortable-0.0.2 | app/controllers/sortable_controller.rb |