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
end
... # more handler code
end
#install routes for the handler
ActionController::Routing::Routes.named_routes.install PdfRenderer