Silly question re: scoping of controller actions


#1

Say that there’s a piece of functionality I want to call everytime the
controller is invoked, regardless of what action I am calling. Where do
I put that, exactly?
Can I do that?


#2

Duane wrote:

Say that there’s a piece of functionality I want to call everytime the
controller is invoked, regardless of what action I am calling. Where do
I put that, exactly?
Can I do that?

Take a look at before_filter. You can specify which method you want
called before any action is called. You can also customize which
actions your filter will apply to.

Jeff
softiesonrails.com


#3

D’oh! I’m already using before_filter for my authorization stuff
anyway. Should ahve thought of that.

Thanks Jeff!

Jeff C. wrote:

Duane wrote:

Say that there’s a piece of functionality I want to call everytime the
controller is invoked, regardless of what action I am calling. Where do
I put that, exactly?
Can I do that?

Take a look at before_filter. You can specify which method you want
called before any action is called. You can also customize which
actions your filter will apply to.

Jeff
softiesonrails.com


#4

Jeff C. wrote:

Duane wrote:

Say that there’s a piece of functionality I want to call everytime the
controller is invoked, regardless of what action I am calling. Where do
I put that, exactly?
Can I do that?

Take a look at before_filter. You can specify which method you want
called before any action is called. You can also customize which
actions your filter will apply to.

Jeff
softiesonrails.com

class MyController < ApplicationController
before_filter :require_login, :except => [:signup, :about]

def require_login
redirect_to :action => ‘signup’ unless session[:user]
end
end