Search code examples
ruby-on-railsrubyruby-on-rails-4elasticsearchsearchkick

How to allow users to search only their posts using Elastic Search with Searchkick on Rails?


I want users to be able to search only their posts and not show the posts created by other users. How exactly would I do that? I'm using Elastic Search with Searchkick gem.

I tried this but it is still showing posts from other users:

posts controller

@posts = current_user.posts.search params[:search]

Solution

  • According to searchkick, the following should work:

    Post.search params[:search], where: {user_id: current_user.id}