S
S
Shaks2017-03-04 17:13:49
Ruby on Rails
Shaks, 2017-03-04 17:13:49

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_committhat 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

I googled an identical issue described in the device issue on github, here - https://github.com/plataformatec/devise/issues/4271
In response, I gave two links, these are:
https://evilmartians.com/chronicles/ new-feature-in...
www.thegreatcodeadventure.com/using-action-control...
The problem is that I can't get request.envand, accordingly, env['warden']in order to feed it manually. I ApplicationController.renderer.new
need help, I couldn't figure it out myself (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Karim Kyatlottyavi, 2017-03-05
@constXife

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 question

Ask a Question

731 491 924 answers to any question