# Some question about before filter in rails 2.02

**URL:** <https://www.ruby-forum.com/t/some-question-about-before-filter-in-rails-2-02/136970>\
**Category:** Rails\
**Created:** [May 7, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/some-question-about-before-filter-in-rails-2-02/136970 "2008-05-07T19:53:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [May 7, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/some-question-about-before-filter-in-rails-2-02/136970/1 "2008-05-07T19:53:47Z")

</div>

Hi guys,  
Following is a simple before filter under rails 2.02

users\_controller.rb

class UsersController \< ApplicationController

skip\_before\_filter :authorize, :only =\> [:login]

## CRUD actions

def login  
if request.post?  
session[:user] = nil  
u = User.find\_by\_email params[:user][:email]  
unless u && u.password\_equal?(params[:user][:password])  
session[:user] = u  
uri = session[:original\_uri]  
session[:original\_uri] = nil  
redirect\_to(uri || {:action =\> :index})  
else  
flash[:notice] = “the user name and email doesn’t match!”  
end  
end  
end

end

application\_controller.rb

class ApplicationController \< ActionController::Base  
helper :all # include all helpers, all the time

# See ActionController::RequestForgeryProtection for details

# Uncomment the :secret if you’re not using the cookie session store

protect\_from\_forgery # :secret =\> ‘4477fc7de98463482e367d7b0d4279eb’

before\_filter :authorize

protected

def authorize  
p “step to authorize”  
unless session[:user]  
flash[:notice] = “please login first…”  
session[:original\_uri] = request.request\_uri  
redirect\_to(:controller =\> “users”, :action =\> “login”)  
end  
end  
end

when I get the url [http://localhost:3000/users](http://localhost:3000/users), it always do loop in  
“authorize”  
action and “step to authorize” appears several times and I got the error

“Redirect Loop  
Firefox has detected that the server is redirecting the request for  
this address in a way that will never complete.  
The browser has stopped trying to retrieve the requested item. The site  
is redirecting the request in a way that will never complete.  
\* Have you disabled or blocked cookies required by this site?  
\* NOTE: If accepting the site’s cookies does not resolve the  
problem, it is likely a server configuration issue and not your  
computer.”

what’s up? It seems it should work well, can anybody point this  
problem?  
I am under ubuntu 8.04 LTS, thanks.
