3

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
Julik
  • 7,676
  • 2
  • 34
  • 48

1 Answers1

1

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

Noah Gibbs
  • 765
  • 3
  • 10
  • 3
    Care to add some sample code? I.e. what is the Rack response I will need to furnish? Or how do I call the controller within the middleware? – Julik Jun 14 '15 at 09:50