Answer the question
In order to leave comments, you need to log in
How to access the request environment from the model?
The chain is as follows:
Bitcoind, upon receipt of funds or at the first confirmation of the transaction, pulls the rake task through walletnotify. That, in turn, performs a series of actions with database models. One of the models has a callback after_commit
that creates an alert ActionCable.broadcast
.
The channel that handles this alert renders partials and distributes them to subscribers via ApplicationController.render
. And everything would be fine, but the partials contain helpers that use request.env
, namely, devise (through pundit, but not the point). And there is nowhere to go from this.
The error looks like this:
ActionView::Template::Error: Devise could not find the `Warden::Proxy` instance on your request environment.
Make sure that your application is loading Devise and Warden as expected and that the `Warden::Manager` middleware is present in your middleware stack.
If you are seeing this on one of your tests, ensure that your tests are either executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` module to inject the `request.env['warden']` object for you
request.env
and, accordingly, env['warden']
in order to feed it manually. I ApplicationController.renderer.new
Answer the question
In order to leave comments, you need to log in
I would suggest rewriting the corresponding partials to account for the fact that you may not have access to request.
Relatively speaking, "if devise_available? && user_signed_in?", and in devise_available write code something like request.present?
Then the templates will work correctly in normal web mode and when launched via Rake.
Or you need to google how Devise is mocked in tests, since tests and Rake have common features - the absence of request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question