Rails 3: How to render ERb template in rake task?

前端 未结 4 1590
无人及你
无人及你 2020-12-25 15:17

I am rendering a pretty huge sitemap HTML file with rake. Unfortunately, the code breaks when I migrate to rails 3. My current code looks like this:

@control         


        
4条回答
  •  臣服心动
    2020-12-25 15:40

    I was successfull by doing something like this:

    class Template < ActionView::Base
      include Rails.application.routes.url_helpers
      include ActionView::Helpers::TagHelper
    
      def default_url_options
        {host: 'yourhost.org'}
      end
    end  
    
    template = Template.new(Rails.root.join('app', 'views'))
    template.assign(attendee: @attendee)
    template.render(template: 'sitemap/index.html.erb')
    

提交回复
热议问题