请问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  

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!mAttached) { mAttached = true; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_TIME_TICK); filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); filter.addAction(Intent.ACTION_USER_SWITCHED); getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); } // NOTE: It's safe to do these after registering the receiver since the receiver always runs // in the main thread, therefore the receiver can't run before this method returns. // The time zone may have changed while the receiver wasn't registered, so update the Time mCalendar = Calendar.getInstance(TimeZone.getDefault()); // Make sure we update to the current time postDelayed(new Runnable() { @Override public void run() { updateClock(); } }, 1000); } private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) { String tz = intent.getStringExtra("time-zone"); mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz)); if (mClockFormat != null) { mClockFormat.setTimeZone(mCalendar.getTimeZone()); } } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { final Locale newLocale = getResources().getConfiguration().locale; if (! newLocale.equals(mLocale)) { mLocale = newLocale; mClockFormatString = ""; // force refresh } } updateClock(); } }; final void updateClock() { if (mDemoMode) return; mCalendar.setTimeInMillis(System.currentTimeMillis()); setText(getSmallTime()); }
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值