Module: Controllers::Sortable

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#perform_sort(record_class) ⇒ Object



13
14
15
16
17
18
19
# File 'app/concerns/controllers/sortable.rb', line 13

def perform_sort(record_class)
  param_name = record_class.name.tableize.singularize
  params[param_name].each_with_index do |id, index|
    record_class.where(id: id).update_all(position: index + 1)
  end
  head :ok
end

#sortObject



9
10
11
# File 'app/concerns/controllers/sortable.rb', line 9

def sort
  perform_sort controller_name.classify.constantize
end