Class: Atreides::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/atreides/base/base.rb,
lib/atreides/base/taggable.rb,
lib/atreides/base/aasmstates.rb,
lib/atreides/base/validation.rb

Overview

Base class inherited by every model in Atreides

Defined Under Namespace

Modules: AasmStates, Taggable, Validation

Instance Method Summary collapse

Instance Method Details

#dom_id(prefix = nil) ⇒ String

Give a DOM friendly ID for an object. This is used extensively with UI Javascript behaviours.

Parameters:

  • prefix (Prefix) (defaults to: nil)

    the id with a custom name. Defaults to the objects model name.

Returns:



33
34
35
36
37
# File 'lib/atreides/base/base.rb', line 33

def dom_id(prefix=nil)
  display_id = new_record? ? "new" : id
  prefix ||= self.class.name.demodulize
  prefix != :bare ? "#{prefix.to_s.parameterize('_')}_#{display_id}" : display_id
end

#to_paramObject

Give a string identifying the model based on it’s properties. In order:

  • slug if it has a property slug

  • id-name if it has a property name

  • id-title if it has a property title

  • id otherwise

Returns:

  • A string describing an instance of a model



23
24
25
26
27
28
# File 'lib/atreides/base/base.rb', line 23

def to_param
  return slug.to_s if self.respond_to?(:slug) and !slug.blank?
  return "#{id}-#{name.to_s.parameterize}" if self.respond_to?(:name) and self.name?
  return "#{id}-#{title.to_s.parameterize}" if self.respond_to?(:title) and self.title?
  id.to_s
end