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?
  end

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

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

class ProspectObserver < ActiveRecord::Observer

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

end

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
-- 
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to