如何允许用户使用SearchKick on Rails使用弹性搜索来搜索他们的帖子?

问题描述:

我希望用户只能搜索他们的帖子,而不显示其他用户创建的帖子。我该怎么做?我正在使用弹性搜索 searchkick gem。

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 = current_user.posts.search params[:search]


根据 searchkick ,以下内容应该有效:

According to searchkick, the following should work:

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