class BlogsController < InheritedResources::Base respond_to :html, :xml before_filter :load_maybe has_scope :tagged_with, :as => :tag belongs_to :user, :optional => true def load_maybe unless params[:user_id] @user = (current_user || User.root) end end def collection @blogs ||= Blog.where(:user_id=>@user.id). paginate(:page => params[:page], :order => 'created_at DESC' ) end protected def begin_of_association_chain @tags = Blog.where(:user_id=>@user.id).tag_counts.sort{|t, u| t.count <=> u.count} return @user end end