Skip to content

Commit

Permalink
solve bug that article list is null for 'will_paginate' in communtiy
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhucheung committed Dec 20, 2016
1 parent 742da40 commit fb41724
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions app/controllers/community_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ def index
def hottest
hottest_articles = Article.hottest
hottest_articles = order hottest_articles
@articles = hottest_articles.paginate page: params[:page], per_page: 15
@articles = hottest_articles.paginate page: params[:page], per_page: 15 unless hottest_articles.blank?
@articles ||= []
articles_during_time hottest_articles
end

def latest
latest_articles = Article.latest
latest_articles = order latest_articles
@articles = latest_articles.paginate page: params[:page], per_page: 15
@articles = latest_articles.paginate page: params[:page], per_page: 15 unless latest_articles.blank?
@articles ||= []
articles_during_time latest_articles
end

Expand All @@ -32,7 +34,8 @@ def tag
return render_404 unless @tag
posted_articles = @tag.articles.where posted: true
@article_size = posted_articles.size
@articles = posted_articles.paginate page: params[:page], per_page: 15
@articles = posted_articles.paginate page: params[:page], per_page: 15 unless posted_articles.blank?
@articles ||= []
end

def articles
Expand Down Expand Up @@ -61,7 +64,8 @@ def articles
Article.where posted: true
end
@article_size = articles.size
@articles = articles.paginate page: params[:page], per_page: 15
@articles = articles.paginate page: params[:page], per_page: 15 unless articles.blank?
@articles ||= []
end

def users
Expand All @@ -76,7 +80,7 @@ def get_user
end

def order(articles)
return nil if articles.blank?
return [] if articles.blank?
case params[:order]
when 'time'
@opt = 0
Expand Down
2 changes: 1 addition & 1 deletion app/views/community/_articles_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% end %>
</div>
</div>
<%= will_paginate articles, renderer: WillPaginate::ActionView::BlogLinkRenderer %>
<%= will_paginate articles, renderer: WillPaginate::ActionView::BlogLinkRenderer unless articles.blank? %>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/community/hottest.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% end %>
</div>
</div>
<%= will_paginate @articles, renderer: WillPaginate::ActionView::BlogLinkRenderer %>
<%= will_paginate @articles, renderer: WillPaginate::ActionView::BlogLinkRenderer unless @articles.blank? %>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm">
Expand Down
2 changes: 1 addition & 1 deletion app/views/community/latest.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% end %>
</div>
</div>
<%= will_paginate @articles, renderer: WillPaginate::ActionView::BlogLinkRenderer %>
<%= will_paginate @articles, renderer: WillPaginate::ActionView::BlogLinkRenderer unless @articles.blank? %>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm">
Expand Down

0 comments on commit fb41724

Please sign in to comment.