aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/refinery/blog/comment.rb16
-rw-r--r--app/models/refinery/blog/post.rb44
2 files changed, 38 insertions, 22 deletions
diff --git a/app/models/refinery/blog/comment.rb b/app/models/refinery/blog/comment.rb
index 55a67ba..d2e9028 100644
--- a/app/models/refinery/blog/comment.rb
+++ b/app/models/refinery/blog/comment.rb
@@ -17,9 +17,19 @@ module Refinery
validates :name, :message, :presence => true
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
- scope :unmoderated, :conditions => {:state => nil}
- scope :approved, :conditions => {:state => 'approved'}
- scope :rejected, :conditions => {:state => 'rejected'}
+ class << self
+ def unmoderated
+ where(:state => nil)
+ end
+
+ def approved
+ where(:state => 'approved')
+ end
+
+ def rejected
+ where(:state => 'rejected')
+ end
+ end
self.per_page = Refinery::Setting.find_or_set(:blog_comments_per_page, 10)
diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb
index c119e44..5c1c6c5 100644
--- a/app/models/refinery/blog/post.rb
+++ b/app/models/refinery/blog/post.rb
@@ -22,7 +22,7 @@ module Refinery
validates :title, :presence => true, :uniqueness => true
validates :body, :presence => true
-
+
validates :source_url, :url => { :if => 'Refinery::Blog.config.validate_source_url',
:update => true,
:allow_nil => true,
@@ -34,24 +34,6 @@ module Refinery
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
- scope :by_archive, lambda { |archive_date|
- where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
- }
-
- scope :by_year, lambda { |archive_year|
- where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
- }
-
- scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) }
-
- scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) }
-
- scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) }
-
- scope :uncategorized, lambda {
- live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } })
- }
-
attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url, :author
attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids
attr_accessible :source_url, :source_url_title
@@ -81,6 +63,30 @@ module Refinery
end
class << self
+ def by_archive(archive_date)
+ where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
+ end
+
+ def by_year(archive_year)
+ where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
+ end
+
+ def all_previous
+ where(['published_at <= ?', Time.now.beginning_of_month])
+ end
+
+ def live
+ where( "published_at <= ? and draft = ?", Time.now, false)
+ end
+
+ def previous(item)
+ where(["published_at < ? and draft = ?", item.published_at, false]).limit(1)
+ end
+
+ def uncategorized
+ live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } })
+ end
+
def next(current_record)
self.send(:with_exclusive_scope) do
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")