We are a software consultancy based in Berlin, Germany. We deliver
high quality web apps in short timespans.

Upstream Agile GmbH

How to get resource route methodes for custom templates in rails

October 08, 2008 by alex

If you write a custom template handler, e.g. for pdf templates you might want to use the rails resource route methods e.g. new_users_path. Here is the way how to get this working for a imaginary PDF template handler.

class PdfRender

    attr_reader :controller
    #delegate the url_for call to the controller

    delegate :url_for, :to => :controller

    def initialize(action_view)
      @action_view = action_view
      @controller = action_view.controller
    ... # more handler code

#install routes for the handler

ActionController::Routing::Routes.named_routes.install PdfRenderer