Class: WhatsonPost

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

Defined Under Namespace

Modules: ShareThis

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.comments_allowed?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'app/models/whatson_post.rb', line 73

def comments_allowed?
  RefinerySetting.find_or_set(:comments_allowed, true, {
    :scoping => 'whatson'
  })
end

.next(current_record) ⇒ Object



67
68
69
70
71
# File 'app/models/whatson_post.rb', line 67

def next current_record
  self.send(:with_exclusive_scope) do
    where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
  end
end

.teaser_enabled_toggle!Object



85
86
87
88
89
90
# File 'app/models/whatson_post.rb', line 85

def teaser_enabled_toggle!
  currently = RefinerySetting.find_or_set(:teasers_enabled, true, {
    :scoping => 'whatson'
  })
  RefinerySetting.set(:teasers_enabled, {:value => !currently, :scoping => 'whatson'})
end

.teasers_enabled?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'app/models/whatson_post.rb', line 79

def teasers_enabled?
  RefinerySetting.find_or_set(:teasers_enabled, true, {
    :scoping => 'whatson'
  })
end

.uncategorizedObject



92
93
94
# File 'app/models/whatson_post.rb', line 92

def uncategorized
  WhatsonPost.live.reject { |p| p.categories.any? }
end

Instance Method Details

#category_ids=(ids) ⇒ Object



56
57
58
59
60
# File 'app/models/whatson_post.rb', line 56

def category_ids=(ids)
  self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
    WhatsonCategory.find(c_id.to_i) rescue nil
  }.compact
end

#friendly_id_sourceObject



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

def friendly_id_source
  custom_url.present? ? custom_url : title
end

#live?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/whatson_post.rb', line 52

def live?
  !draft and published_at <= Time.now
end

#nextObject

next is now in << self



44
45
46
# File 'app/models/whatson_post.rb', line 44

def next
  WhatsonPost.next(self).first
end

#prevObject



48
49
50
# File 'app/models/whatson_post.rb', line 48

def prev
  WhatsonPost.previous(self).first
end