Andreas Schneider wrote:
Hi all,
perhaps I am on the wrong path - because I come from the ASP world
I want that my app checks on every page if my user is logged in or not. I have 2 cookies set in my signin process - which works great. now I want to set a global var if a user is logged in or not I do that in the application controller
class ApplicationController < ActionController::Base
$login_user_id = cookies[:user_id] $login_user_sid = cookies[:user_sid] if $login_user_id != "" $login_ok = true else $login_ok = false end
end
but this will not work - he cant access the cookies
error >> undefined local variable or method `cookies' for ApplicationController:Class
what I am doing wrong?
thanks for any help in my path to escape the MS ASP world andreas
Hey
You could write an action that just checks those cookies...
class ApplicationController < ActionController::Base
def login_ok? !cookies[:user_id].blank? end
end
Then in some other action in say, your store_controller? use
def show_store if login_ok? render :layout => 'store' else flash[:warning] = 'not allowed there!' redirect_to :action => 'not_allowed' end end
Or something similar, I'm not very big on cookies, but this seems like it should work :]
Cheery-o Gustav Paul gustav@rails.co.za