0

是否有可能我不仅为 before_filter 定义了一个动作,而且还为动作的控制器定义了一个动作?我想将 before_filter 方法放入我的 application_controller 但是当我在那里定义时,例如:

before_filter :authorize, except: [:index]

所有具有索引操作的控制器都会受到影响!我想写这样的东西:

before_filter :authorize, except: [user#index]

谢谢

4

2 回答 2

1

你不能做你所要求的。你能做的是

class ApplicationController < ActionController::Base
  before_filter :authorize
  ...
end


class UsersController < ApplicationController
  skip_before_filter :authorize, :only => [:index]
  ...
end
于 2013-10-16T20:10:14.563 回答
0

为什么不将 before 过滤器放在您的 users_controller 中?

class UsersController < ApplicationController
  before_filter :authorize, except: [:index]
  ...
end
于 2013-10-16T20:00:32.920 回答