在CanCan中跳过一个rails操作

Vin*_*e W 0 authorization ruby-on-rails cancan ruby-on-rails-3

我有一个带有一些常规方法的用户控制器.我的ability.rb已设置但我需要未登录的用户才能处理这一操作.我已经在我的ability.rb中为未登录的用户尝试了以下所有内容,但它没有任何区别......我仍然收到未经授权的错误.

can :create, User
can :update, User
can :edit, User
can :modify, User
Run Code Online (Sandbox Code Playgroud)

接下来我尝试在我的ability.rb中创建一个条目

can :do_this_action, User
Run Code Online (Sandbox Code Playgroud)

并将其放在用户控制器中

authorize!(:can_do_this_action, User.new || @user)
Run Code Online (Sandbox Code Playgroud)

仍然没有运气..

最后,我试图跳过这个动作.我在用户控制器中用它做了这个:

skip_authorization_check :only => [:create, :new, :custom_method ]
authorize_resource
Run Code Online (Sandbox Code Playgroud)

这仍然给我的自定义方法一个未经授权的错误 任何人都知道我哪里出错了?提前致谢.

Sim*_*ton 5

尝试使用这个助手就像:before_filter:

load_and_authorize_resource :only => [:index, :show] #or use :except
Run Code Online (Sandbox Code Playgroud)