如何允许用户使用SearchKick on Rails使用弹性搜索来搜索他们的帖子? [英] How to allow users to search only their posts using Elastic Search with Searchkick on Rails?
本文介绍了如何允许用户使用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}
这篇关于如何允许用户使用SearchKick on Rails使用弹性搜索来搜索他们的帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文