簡體   English   中英

不僅為before_filter定義動作,還為控制器定義動作

[英]Not only define action for before_filter but also controller

我是否不僅可以為before_filter定義一個動作,而且可以為該動作的控制器定義一個? 我想將before_filter方法放到我的application_controller中,但是當我在其中定義例如時:

before_filter :authorize, except: [:index]

所有具有索引動作的控制器都會受到影響! 我想寫下這樣的話:

before_filter :authorize, except: [user#index]

謝謝

你不能做你想要的。 你能做的是

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


class UsersController < ApplicationController
  skip_before_filter :authorize, :only => [:index]
  ...
end

為什么不將before過濾器放入users_controller中?

class UsersController < ApplicationController
  before_filter :authorize, except: [:index]
  ...
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM