ruby-on-railsurlhelper

How do I include routes.url_helpers into a view renderer in rails?


I am trying to render html in my model (for Mandrill inline code) but i cant seem to get the url_helpers to render correctly

questions.haml

 %a{:href => email_question_url(question)}

model.rb

  view = ActionView::Base.new(ActionController::Base.view_paths, @email_vars)
  view.extend ApplicationHelper
  questions_html = view.render(:partial => 'transactional_mailer/questions_html')

I ideally want to run:

      view.include Rails.application.routes.url_helpers

But that bombs out with undefined method include for actioniew::base

Any suggestions on how i could approach this?


Solution

  • I had to open the instance class and include the instance methods within it via:

      view = ActionView::Base.new(ActionController::Base.view_paths,{})
    
      class << view
        include Rails.application.routes.url_helpers
      end
    
      questions_html = view.render(:partial => 'transactional_mailer/questions_html')