I am setting up a Rails 2.0 project where i am using
acts_as_authenticated as my user 'manager'. I am trying to use the
scope_out plugin to group users into a Account. In order for that to
work i need to use the current_user inside the User Model. The most
obvious approach would be to use the example below and set the current
user inside the application controller. However this is just not
working. My current_user accessor stays empty inside the User model. Is
this because i am running in development mode or is this a known Rails
2.0 issue. Do you guys know any alternatives.
class ApplicationController < ActionController::Base
before_filter do |c|
User.current_user = User.find(c.session[:user].id) unless
c.session[:user].nil?
end
end
class User < ActiveRecord::Base
cattr_accessor :current_user
end
I am setting up a Rails 2.0 project where i am using
acts_as_authenticated as my user 'manager'. I am trying to use the
scope_out plugin to group users into a Account. In order for that to
work i need to use the current_user inside the User Model. The most
obvious approach would be to use the example below and set the current
user inside the application controller. However this is just not
working. My current_user accessor stays empty inside the User model.
Is
this because i am running in development mode or is this a known Rails
2.0 issue. Do you guys know any alternatives.
Isn't the thing in the session normally :user_id ?
This is one of these cases where I'd just advise not to use the
scope_out plugin. I don't know what you're trying to do, but it feels
wrong when your User model needs data from the session to function.
Seems like things could be better structured. Since you're using
acts_as_authenticated you could:
class ApplicationController < ActionController::Base
include AuthenticatedSystem
before_filter :login_required, :set_current_user
protect
def set_current_user
User.current_user = self.current_user
end
end
I disagree slightly with Jan. Jan is right that this application
seems to be too tightly coupled to the Controller. scope_out,
however, still may be appropriate to your needs... but your
application of it does seem off.