Module: RailsSortable::Model

Defined in:
app/models/rails_sortable/model.rb

Overview

Include this module to your ActiveRecord model. And you must call ‘set_sortable` method for using sortable model.

ex) class SampleModel < ActiveRecord::Base

include RailsSortable::Model
set_sortable :sort, without_updating_timestamps: true

end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
16
17
18
# File 'app/models/rails_sortable/model.rb', line 13

def self.included(base)
  base.class_eval do
    before_create :maximize_sort
  end
  base.extend ClassMethods
end

Instance Method Details

#update_sort!(new_value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/rails_sortable/model.rb', line 20

def update_sort!(new_value)
  write_attribute sort_attribute, new_value
  if self.class.sortable_options[:silence_recording_timestamps]
    warn "[DEPRECATION] `silence_recording_timestamps` is deprecated. Please use `without_updating_timestamps` instead."
    without_updating_timestamps { save! }
  elsif self.class.sortable_options[:without_updating_timestamps]
    without_updating_timestamps { save! }
  else
    save!
  end
end