Providing an "internal" Rails controller from middleware

I have Rails intermediate content and I have an MW part outside of ActionDispatch. Ideally, I would like to render the page using ActionDispatch, initiating a URL that is internal (not accessible via normal URL routes) - similar to how Devise renders "auth failed" error pages. Your best bet would be to just call one specific controller action in the application by name and return the render result (without its uniform route).

What's the standard, modern way of doing this?

UPDATE

def call(env)
  if user_from_env(env).free_accout?
    InterestingPagesController.action(:how_to_signup).call(env)
  else
    @app.call(env)
  end
end

      

+3


source to share


1 answer


You can return the controller action as a rack endpoint using controller.action, then call the endpoint using endpoint.call () or endpoint [].



+1


source







All Articles