Yes, you can access your AR samples from your middleware. I added byebug to my middleware and was able to access my models.
EDIT: - So, I started writing Rack middleware for use in my Rails application. I tried to access my AR model in middleware, but its behavior was pretty funny. Everything will be fine for the first request filed after starting a new server. But any request that came after this led to an error: -
A copy of MyMiddleware has been removed from the module tree, but is still active
This error disappeared as soon as I stopped accessing the AR model from middleware. I just started with Ruby / Rails, so I donβt know specific terms in the world of Ruby / Rails / Rack. But in simple words, all I can say is that Rack middleware is a kind of plug and play library that anyone can use in any Rack application. Therefore, we should not depend on any Rails objects inside our middleware.
source share