Marnen Laibow-Koser wrote:
> Ralph Shnelvar wrote:
> [...]
>> Here's another question:
>> Is the before_filter ever called before methods in 
>> ApplicationController?
> 
> Yes. (Try it and find out!)  Most authentication libraries work this 
> way.  Doesn't Devise?
> 
> Best,
> -- 
> Marnen Laibow-Koser
> http://www.marnen.org
> [email protected]
> 
> Sent from my iPhone

What prevents 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
    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.
-- 
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