Sha256: 917193bfc66c987b4f8ccddda635762a1a92cb86179ad31c2776c7ed219aab34
Contents?: true
Size: 516 Bytes
Versions: 26
Compression:
Stored size: 516 Bytes
Contents
module Idx extend ActiveSupport::Concern included do # ------------------------------------------ Scopes scope :by_idx, -> { reorder('idx asc') } # ------------------------------------------ Callbacks after_create :create_idx end # ------------------------------------------ Instance Methods def to_param idx.to_s end def create_idx last_obj = self.idx_class.send(self.class.table_name).by_idx.last idx = last_obj.idx + 1 update_columns(:idx => idx) end end
Version data entries
26 entries across 26 versions & 2 rubygems