请问before_filter是不是只能在action方法之前执行?

请问before_filter是不是只能在action方法之前执行,在非action方法之前不执行呢?
我试了在index action时执行,但如果我放在index的子方法前就不执行了,是这样吗?
例:

   index为action方法,subm为自定义非action方法。

1 这样可以正常执行。

  1. class TestController < ApplicationController 
  2.    before_filter :filterm,:only=>[:index]   
  3.   
  4.    def index   
  5.    end  
  6.   
  7.    def filterm   
  8.    end  
  9. end  

 2 这样不执行正常,在执行subm之前并不会执行filterm。

  1. class TestController < ApplicationController    
  2.    before_filter :filterm,:only=>[:subm]   
  3.   
  4.    def index   
  5.       subm   
  6.    end  
  7.   
  8.    def subm   
  9.    end  
  10.   
  11.    def filterm   
  12.    end  
  13. end  

请问各位知道的朋友,可不可以告诉为什么?

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值