class ApplicationController < ActionController::Base
before_action :test, only: [:index]
def test
ap 'test'
end
end
위의 코드는 dog # index 또는 cats # index 또는 rabbits # index가 될 때마다 실행됩니다. cat # index와 rabbit # index 바로 전에 어떻게 실행해야합니까?특정 컨트롤러의 before_action
많은 컨트롤러에서 작업 전에 실행되도록 테스트하고 싶습니다.
을 컨트롤러이 작업의 재치있는 하위 범주가있는 경우 적용될 때 상속 체인에 소개 할 수 있습니다 :'class FluffyPetsController
DaveMongoose
^좋은 추가. 어떤 상황에서는이 호출에서'before_action'을 섞는 모듈을 요구할 수도 있습니다. ('클래스 CatsController
http://stackoverflow.com/questions/11940253/where-to-put-a-before-filter-shared-between-multiple-controllers 예제를 제공합니다. 모듈 기반 솔루션 – DaveMongoose