Rendering an "internal" Rails controller from a middleware

1k views Asked by At

I have a Rails middleware stack, and I have a piece of MW outside ActionDispatch. Ideally I would like to render a page using ActionDispatch by triggering a URL which is internal (not accessible via usual URL routes) - similar to the way Devise renders it's "auth failed" pages. The best thing would be to just trigger one specific controller action in the application by name, and return it's render result (without having it in the routes even).

What is 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
1

There are 1 answers

1
Noah Gibbs On BEST ANSWER

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