Class: Portfolio::SiteItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/portfolio/site_item.rb

Direct Known Subclasses

SiteProject

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.display_nameObject



54
55
56
# File 'app/models/portfolio/site_item.rb', line 54

def self.display_name
  nil
end

.group_by_categoriesObject



40
41
42
# File 'app/models/portfolio/site_item.rb', line 40

def self.group_by_categories
  SiteItemCategory.where(id: self.select(:site_item_category_id))
end

.human_nameObject



62
63
64
# File 'app/models/portfolio/site_item.rb', line 62

def self.human_name
  self.resource_name.split('_').last
end

.resource_nameObject



58
59
60
# File 'app/models/portfolio/site_item.rb', line 58

def self.resource_name
  self.name.underscore.split('/').last
end

.subclassesObject

overriding .subclasses because its an empty array at the time of constructing the routes



46
47
48
# File 'app/models/portfolio/site_item.rb', line 46

def self.subclasses
  [SiteProject]
end

.subclasses_namesObject



50
51
52
# File 'app/models/portfolio/site_item.rb', line 50

def self.subclasses_names
  subclasses.map { |d| d.name.underscore.split('/').last }
end

Instance Method Details

#default_imageObject



27
28
29
30
31
32
33
# File 'app/models/portfolio/site_item.rb', line 27

def default_image
  if site_item_images.empty?
    nil
  else
    site_item_images.default.first || site_item_images.first
  end
end

#default_image_url(style = :medium) ⇒ Object



35
36
37
38
# File 'app/models/portfolio/site_item.rb', line 35

def default_image_url style=:medium
  image = default_image
  image ? image.image.url(style) : nil
end

#path_keyObject



19
20
21
# File 'app/models/portfolio/site_item.rb', line 19

def path_key
  "#{path_title}-#{id}"
end

#path_titleObject



23
24
25
# File 'app/models/portfolio/site_item.rb', line 23

def path_title
  title.parameterize('-')
end