Module: AbAdmin::Concerns::Utilities

Extended by:
ActiveSupport::Concern
Defined in:
lib/ab_admin/concerns/utilities.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#compare_keyObject


117
118
119
# File 'lib/ab_admin/concerns/utilities.rb', line 117

def compare_key
  "#{self.class.model_name.singular}_#{id}"
end

#ensure_token(column = :guid) ⇒ Object


128
129
130
131
132
133
# File 'lib/ab_admin/concerns/utilities.rb', line 128

def ensure_token(column=:guid)
  return self[column] if self[column].present?
  generate_token(column)
  update_column(column, self[column]) unless new_record?
  self[column]
end

#generate_token(column = :guid) ⇒ Object


121
122
123
124
125
126
# File 'lib/ab_admin/concerns/utilities.rb', line 121

def generate_token(column=:guid)
  begin
    self[column] = AbAdmin.friendly_token
  end while self.class.exists?(column => self[column])
  self[column]
end