Skip to content
Browse files

Converted scopes to class methods as scopes are not recommended anymore.

  • Loading branch information...
1 parent c96a3ad commit 326327a9b4e6c76a783f5df22c6972d6ccedb836 @parndt parndt committed
Showing with 29 additions and 10 deletions.
  1. +5 −1 app/models/forem/post.rb
  2. +24 −9 app/models/forem/topic.rb
View
6 app/models/forem/post.rb
@@ -10,7 +10,11 @@ class Post < ActiveRecord::Base
delegate :forum, :to => :topic
- scope :by_created_at, order("created_at asc")
+ class << self
+ def by_created_at
+ order("created_at asc")
+ end
+ end
validates :text, :presence => true
after_create :subscribe_replier
View
33 app/models/forem/topic.rb
@@ -15,13 +15,28 @@ class Topic < ActiveRecord::Base
before_save :set_first_post_user
after_create :subscribe_poster
- scope :visible, where(:hidden => false)
- scope :by_pinned, order('forem_topics.pinned DESC, forem_topics.id')
- scope :by_most_recent_post, joins(:posts).select("DISTINCT forem_posts.topic_id, forem_topics.*, forem_posts.created_at").order('forem_posts.created_at DESC, forem_topics.id')
- scope :by_pinned_or_most_recent_post, includes(:posts).
- order('forem_topics.pinned DESC').
- order('forem_posts.created_at DESC').
- order('forem_topics.id')
+ class << self
+ def visible
+ where(:hidden => false)
+ end
+
+ def by_pinned
+ order('forem_topics.pinned DESC, forem_topics.id')
+ end
+
+ def by_most_recent_post
+ joins(:posts).
+ select("DISTINCT forem_posts.topic_id, forem_topics.*, forem_posts.created_at").
+ order('forem_posts.created_at DESC, forem_topics.id')
+ end
+
+ def by_pinned_or_most_recent_post
+ includes(:posts).
+ order('forem_topics.pinned DESC').
+ order('forem_posts.created_at DESC').
+ order('forem_topics.id')
+ end
+ end
def to_s
subject
@@ -61,13 +76,13 @@ def register_view_by(user)
view.increment!("count")
end
end
-
+
def subscribe_poster
subscribe_user(self.user_id)
end
def subscribe_user(user_id)
- if user_id && !subscriber?(user_id)
+ if user_id && !subscriber?(user_id)
subscriptions.create!(:subscriber_id => user_id)
end
end

0 comments on commit 326327a

Please sign in to comment.
Something went wrong with that request. Please try again.