Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ def update
end

def index
@posts = Post.all
@posts = Post.published
if params[:query].present?
@posts = Post.search(params[:query]).order('views_count DESC , created_at DESC')
else
@posts = Post.published.order('views_count DESC , created_at DESC')
@posts = @posts.search(params[:query])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@babiracka I don't know Ruby that much… Do u really need to override @post?

Instead of doing this:
@posts = @posts.search(params[:query])

Is it possible to do just this?
@posts.search(params[:query])

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you would need to reassign the results of @posts.search back to @posts. Such method calls does not change the original object the method is called on. It just returns the value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishijain ok, thx

end
Statistic.increment_counter(:count, Statistic.home_page_view_count.id)
@posts = @posts.order('views_count DESC, created_at DESC')
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@babiracka bring the incrementation back

def show
Expand Down