How to get Devise current_user method in Rails Engine

I have a Rails application using the Devise stone and I am creating a Rails Engine to mount in this application.

mount Comments::Engine => '/talk', :as => 'comments'

Inside Engine, I want to get an instance current_userfrom the main application.

At {main_app} /initializers/comments.rb

Comments.user_class = "User"
Comments.current_user = "current_user" #current_user is Devise method(works fine in app)

In {engine} /lib/comments.rb

require "comments/engine"

module Comments
  mattr_accessor :user_class, :current_user

  def self.user_class
    @@user_class.constantize
  end

  def self.current_user
    send(@@current_user)
  end
end

When I call Comments.current_user, I get the error "incorrect constant name current_user".

What am I doing wrong?

+2
source share
1 answer

. current_user , . current_user . (.

-1

All Articles