Forum: Ruby on Rails Silly question re: scoping of controller actions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A24e589de07cb769a71f28aead957a48?d=identicon&s=25 Duane (Guest)
on 2006-06-07 20:37
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?
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2006-06-07 20:52
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
A24e589de07cb769a71f28aead957a48?d=identicon&s=25 Duane (Guest)
on 2006-06-07 20:54
D'oh!  I'm already using before_filter for my authorization stuff
anyway.  Should ahve thought of that.

Thanks Jeff!

Jeff Cohen 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
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-06-07 20:55
Jeff Cohen 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
This topic is locked and can not be replied to.