我的routes.rb
下面有以下内容:
resources :users do
resources :submitted_terms, only: [:index, :create, :show]
end
我只希望current_user
(登录用户)能够根据submitted_terms
和index
视图查看自己的show
。他们不应该看到任何其他人的index
和show
观点,其他人也不应该看到他们的观点。
我想我知道如何实现这一点但对我来说感觉有些混乱。有什么想法吗?
答案 0 :(得分:0)
你可以在before_action过滤。
before_action :correct_user, only: [#action for which you need this filer]
def correct_user
@submitted_term = SubmittedTerm.find(params[:id])
unless @submitted_term.user == current_user
flash[:notice] = "Insuffient privlage"
redirect_to #some path or render
end
end
您可能需要更改代码或创建新操作(过滤器)以检查用户是否已登录