为特定控制器 Rails 的特定操作跳过登录

Has*_*ikh 3 ruby-on-rails devise cancan

我在 Rails 应用程序中使用 Devise 和 CanCan。我的问题是我想basket_public_url为特定控制器 ( BasketsController) 公开特定操作 ( ) 。我知道如何跳过控制器进行授权。有办法吗?

https://github.com/ryanb/cancan/wiki/Ensure-Authorization#conditionally-check-authorization

Opt*_*tte 5

如果您想跳过登录,这意味着您要绕过身份验证和授权。

class BasketsController < ApplicationController
  skip_before_action :authenticate_user!, :only => :basket_public_url
  skip_authorize_resource :only => :basket_public_url

end
Run Code Online (Sandbox Code Playgroud)