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

强颜欢笑 提交于 2019-12-11 11:16:15

问题


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]

回答1:


According to searchkick, the following should work:

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



回答2:


Maybe you need to add a where clause to only search the post of the user

@posts = current_user.posts.where(user_id: current_user.id).search(params[:search])


来源:https://stackoverflow.com/questions/27888407/how-to-allow-users-to-search-only-their-posts-using-elastic-search-with-searchki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!