0

Is it possible to use something like current_user or User.current in the initializers? I've tried something like

Something = Something::Some.new configure do |something|

    something.somethingelse = current_user.key

end

but it states it can't find the key but I know that key is a column in User table. I can do something = current_user.key or something = User.key in under model or controller and it works fine.

user2419316
  • 331
  • 3
  • 15

1 Answers1

1

current_user is usually set in the application_controller of your application. If you use a gem like Devise to handle user authentications for example, they take care of setting such method for you.

The initializers' code is executed when you launch your application on your server (local machine or remote server), therefor you understand that a "current_user" (understand a "logged in" user) simply does not exists (yet).

Pierre-Louis Gottfrois
  • 17,561
  • 8
  • 47
  • 71