Class: Atreides::Base
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Atreides::Base
- 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
Direct Known Subclasses
ContentPart, Feature, Like, LineItem, Link, Message, Order, Page, Photo, Post, Preferences, Product, Site, Size, Tweet, User, Video, Vote
Defined Under Namespace
Modules: AasmStates, Taggable, Validation
Instance Method Summary collapse
-
#dom_id(prefix = nil) ⇒ String
Give a DOM friendly ID for an object.
-
#to_param ⇒ Object
Give a string identifying the model based on it’s properties.
Instance Method Details
#dom_id(prefix = nil) ⇒ String
Give a DOM friendly ID for an object. This is used extensively with UI Javascript behaviours.
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_param ⇒ Object
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
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 |