Ralph Shnelvar wrote:
[...]
> What prevents infinite recursion?

What would cause infinite recursion?

> 
> 
> - - - - -
> class ApplicationController < ActionController::Base
>   before_filter    :fetch_logged_user
>   before_filter    :authenticate,          :except => :login
> 
> # Filters added to this controller apply to all controllers in the 
> application.
> # Likewise, all the methods added will be available for all controllers.
> 
> class ApplicationController < ActionController::Base
>   before_filter    :fetch_logged_user
>   before_filter    :authenticate,          :except => :login
> 
>   helper :all # include all helpers, all the time
>   protect_from_forgery
> 
> 
>   def fetch_logged_user
>     unless session[:user_id].blank?
>       @logged_user = User.find(session[:user_id])
>     end
> 
>   rescue ActiveRecord::RecordNotFound
>   end
> 
> 
>   def is_logged_in_user?
>     !...@logged_user.nil?
>   end
> 
> protected
>   def authenticate
>     debugger
>     unless @logged_user
>       #unauthorized access
>       redirect_to :controller => :welcome, :status => 401
>       return false
>     end
>   end
> end
> 
> 
> 
> class ExplanationController < ApplicationController
>   def whatIsThisGameAbout

Hey!  Watch the camelCase!  That should be what_is_this_game_about .
Actually, it should probably game_info or something.

>     x = is_logged_in_user?
>     debugger
>     x
>   end
> 
> 
> protected
>   def authenticate
>     debugger
>     x=1
>   end
> 
> end
> - - - - -
> 
> 
> I am pretty sure that when Rails calls the action whatIsThisGameAbout 
> that when is_logged_in_user? is invoked that the before_filters are NOT 
> invoked again before is_logged_in_user? is invoked.

You're quite right.  When you do a straight method call, the filter 
chain is not invoked -- after all, it's just a straight method call, and 
it works just like it does anywhere else in Ruby.  It's only invoked 
when you call a controller method *as an action* -- that is, when you go 
through the whole Rails stack, as with a Web request or with render 
:controller, :action -- that the filter chain is invoked.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to