Written by Sean Behan on Sun Jun 17th 2012

Take advantage of the named_scope method in your models and make find queries simple and beautiful!

#app/models/comment.rb
class Comment < ActiveRecord::Base
  belongs_to :post
  named_scope :pending, :conditions => ["pending = ?", true]
  named_scope :for, lambda { |*args| {:include => :post,
      :conditions => ["posts.account_id = ?", (args.first||0)] }}
end

app/models/post.rb

class Post < ActiveRecord::Base has_many :comments end

Now you can get all comments for your posts that are marked as pending with this method:
@comments = Comment.pending.for(@account.id)

Tagged with..
#Ruby on Rails

Just finishing up brewing up some fresh ground comments...