From 1285ec5ced9b9c13c05569af69aa7468d39cf2de Mon Sep 17 00:00:00 2001 From: babiracka Date: Fri, 7 Aug 2015 10:22:56 +0200 Subject: [PATCH 1/2] search is no longer showing posts in draft/published state + query is not repeated --- app/controllers/posts_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a8d0b7a..b0ef798 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -29,13 +29,12 @@ def update end def index - @posts = Post.all + @posts = Post.published.order('views_count DESC, created_at DESC') if params[:query].present? - @posts = Post.search(params[:query]).order('views_count DESC , created_at DESC') + @posts = @posts.search(params[:query]) else - @posts = Post.published.order('views_count DESC , created_at DESC') + @posts = @posts end - Statistic.increment_counter(:count, Statistic.home_page_view_count.id) end def show From 8c17a48d80ce19f0c4615f5d755aa97c34e8353e Mon Sep 17 00:00:00 2001 From: babiracka Date: Fri, 7 Aug 2015 10:38:22 +0200 Subject: [PATCH 2/2] search is no longer showing unpublished posts. --- app/controllers/posts_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index b0ef798..b31cee8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -29,12 +29,11 @@ def update end def index - @posts = Post.published.order('views_count DESC, created_at DESC') + @posts = Post.published if params[:query].present? @posts = @posts.search(params[:query]) - else - @posts = @posts end + @posts = @posts.order('views_count DESC, created_at DESC') end def show