How to get resource route methodes for custom templates in rails

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

Tags: , ,

Leave a Reply