【发布时间】:2010-06-18 00:52:44
【问题描述】:
我正在尝试将生成站点地图的逻辑封装在一个单独的类中,以便我可以使用 Delayed::Job 在带外生成它:
class ViewCacher
include ActionController::UrlWriter
def initialize
@av = ActionView::Base.new(Rails::Configuration.new.view_path)
@av.class_eval do
include ApplicationHelper
end
end
def cache_sitemap
songs = Song.all
sitemap = @av.render 'sitemap/sitemap', :songs => songs
Rails.cache.write('sitemap', sitemap)
end
end
但每当我尝试ViewCacher.new.cache_sitemap 时,我都会收到此错误:
ActionView::TemplateError:
ActionView::TemplateError (You have a nil object when you didn't expect it!
The error occurred while evaluating nil.url_for) on line #5 of app/views/sitemap/_sitemap.builder:
我认为这意味着ActionController::UrlWriter 没有包含在正确的位置,但我真的不知道
【问题讨论】: