5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/blog/papers_controller.rb', line 5
def index
if params[:tag_name]
@tags = ActsAsTaggableOn::Tagging.all(:include => :tag, :conditions => { :tags => { :name => params[:tag_name].humanize }})
else
@category = PaperCategory.find_by_url(params[:blog_category_id]) || PaperCategory.find_by_id(params[:blog_category_id]) if params[:blog_category_id]
end
paginate_options = {:page => page, :per_page => per_page, :conditions => { :state => 'published'}}
case params[:sort_by]
when 'popularity'
paginate_options[:order] = "sum(#{PaperViewedCounter.table_name}.counter) DESC, papers.id DESC"
paginate_options[:include] = :viewed_counters
paginate_options[:group] = "papers.id"
when 'commented'
paginate_options[:order] = "COUNT(#{Comment.table_name}.id) DESC, papers.id DESC"
paginate_options[:include] = :comments
paginate_options[:group] = "papers.id"
else
paginate_options[:order] = 'papers.published_at DESC, papers.id DESC'
end
if params[:tag_name]
@paper = @tags.collect{ |t| t.papers }.paginate(paginate_options)
else
@papers = @category ? @category.elements.paginate(paginate_options) : Paper.paginate(paginate_options)
end
respond_to do |format|
format.html
format.atom
format.xml
format.
end
end
|