我正在努力使它成为一个Devise用户必须在Rails控制器的show动作上进行身份验证,除非show是某个id。那可能吗?是否有以下内容?
before_action :authenticate_user!, except: [:show id: 1]
答案 0 :(得分:2)
skip_before_filter :authenticate_user!, :only => :show, :if => "Provide Condition"
在您的案例ID中,使用上述语法跳过特定情况的身份验证。
答案 1 :(得分:1)
所以我想通了。
skip_before_filter :authenticate_user!, :only => :show, :if => lambda {
if params[:id]
@post = Post.find(params[:id])
if @post.id == 1
else
false
end
}