Forum: Ruby on Rails current_user in a model observer

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bharat R. (Guest)
on 2009-04-20 18:43
I need to get the current_user id in my model observers:

Here is the code for current_user in the lib/authentication.rb file:

module Authentication
  def self.included(controller)
    controller.send :helper_method, :current_user, :logged_in?,
:has_role?, :is_admin?

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]

Here is the propsect_observer.rb file in models directory which needs

class ProspectObserver < ActiveRecord::Observer

  def after_update(prospect)
    prospect.comments.create(:content => @comment_text, :admin_only =>
      :commenter_id => if @comment_text


current_user is not recognized here.  I could include the module in the
observer, but that is bad(?).  Any suggestion on a good alternative?

Thanks for your time.

Bharat R. (Guest)
on 2009-04-20 19:42
Forget it.  Bad design.  I am not pursuing this path anymore.
This topic is locked and can not be replied to.