In Ruby on Rails, popular restful_authentication and login_sugar all have a variable @current_user set. After I installed the admin plugin, I browsed into the code, and seems there is a CurrentUser variable set in somewhere. However I have no luck to use it.
Then I tried to add these into my ApplicationController: function __construct() { $this->beforeFilter('load_current_user'); ... }
In another controller: function order() { if(empty($this->CurrentUser)){ $this->redirectTo('/account/sign_in'); } else { $this->redirectTo('/order/start'); } }
It seems that CurrentUser is not set even though I have logged in. Any clue?
ps: Any particular reason to use role based control instead of typical RoR behavior below? before_filter :authenticate_user, :except => [ :login, :signup, :forgot_password, :validate] before_filter :wizard_required, :only => [:index, :list, :new, :create, :edit, :update, :destroy]
CommentAuthorkelyar
try running it as before_filter in application_controller
function getCurrentUser() { Ak::import('sentinel,user'); $Sentinel =& new Sentinel(); $Sentinel->init($this); $this->CurrentUser = &$Sentinel->getUserFromSession(); return true; }
this will give you $this->CurrentUser in controllers and $controller->CurrentUser in views