views:

71

answers:

1

Hi,

I have this funny situation whereby I see my before_filter executing multiple times for one access.

My filter is called auth_user_filter and it logs using logger.info("Yada Yada Yada"). It gets set globally to run before all actions. When I access an action over my browser it prints the following (depending on what call it is)

The first call prints

 Yada Yada Yada

The second call prints

 Yada Yada Yada
 Yada Yada Yada

The third call prints

 Yada Yada Yada
 Yada Yada Yada
 Yada Yada Yada

And so on.

This only happens in development mode and I was wondering if anybody knows why?

+2  A: 

How exactly are you setting it globally? Sounds like the before_filter :foo is being called on something that is not reloaded (possibly ActionController::Base) from a file that is being reloaded (like a controller file).

If this is so, move the before filter to the ApplicationController, or move the before_filter call to an initializer.

cwninja
I have the before_filter code in UserManagementApplicationConreoller. And I have ApplicationController < UserManagementApplicationController < ActionController::BaseI do this because UserManagement is a Rails Engine plugin I use in many of my apps. So defining the code in there makes it a lot more DRY. Then any apps that use this plugin I just have ApplicationController inherit UserManagementApplicationController versus ActionController::Base.I am not sure if your suggestion explains why it only happens in Development mode though and not in Production. Thanks for input.
Will