Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==== Error
- ActiveRecord::StatementInvalid (PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
- LINE 1: ...comments ON comments.post_id = posts.id ORDER BY comments.c...
- ^
- : SELECT distinct posts.* FROM "posts" INNER JOIN comments ON comments.post_id = posts.id ORDER BY comments.created_at DESC LIMIT 5):
- app/models/comment_activity.rb:18:in `find_recent'
- app/controllers/admin/dashboard_controller.rb:4:in `show'
- ===== Controller
- class Admin::DashboardController < Admin::BaseController
- def show
- @posts = Post.find_recent(:limit => 8)
- @comment_activity = CommentActivity.find_recent
- @stats = Stats.new
- end
- end
- ===== Method
- class CommentActivity
- attr_accessor :post
- def initialize(post)
- self.post = post
- end
- def comments
- @comments ||= post.approved_comments.find_recent(:limit => 5)
- end
- def most_recent_comment
- comments.first
- end
- class << self
- def find_recent
- Post.find(:all,
- :select => 'distinct posts.*',
- :joins => 'INNER JOIN comments ON comments.post_id = posts.id',
- :order => 'comments.created_at DESC',
- :limit => 5
- ).collect {|post|
- CommentActivity.new(post)
- }.sort_by {|activity|
- activity.most_recent_comment.created_at
- }.reverse
- end
- end
- end
Add Comment
Please, Sign In to add comment