Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/search #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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

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
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

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

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