【发布时间】:2011-11-09 19:31:21
【问题描述】:
我知道这不是“可接受的”做法,但作为后台进程,我将渲染的 Rails 部分缓存到数据库中,以便通过 JSONP 更快地输出。我在该主题上找到了许多资源,并在 ActiveRecord 模型中成功输出了 Rails 2.3.x 部分,但是如果我在部分 Rails 中使用动态 URL 就会爆炸。
我得到一个成功的输出(减去动态 URL)...
def self.compile_html
viewer = Class.new(ApplicationController)
path = ActionController::Base.view_paths rescue ActionController::Base.view_root
Question.all.each do |q|
q.html = ActionView::Base.new(path, {}, viewer).render(:partial => "questions/cached_output", :locals => { :question => q })
sleep 1 # hold for complete output and debugging only
q.save( false ) # bypass validations
end
return "Caching complete"
end
我尝试包含ActionController::UrlWriter 模块和ActionView::Helpers::UrlHelper,但没有成功。我似乎找不到允许部分访问ActionController::Base.new.url_for() 以将动态路由写入部分的实例化/包含顺序。
我确实尝试了与 RoR: undefined method `url_for' for nil:NilClass 类似的过程,但没有运气
我知道 render_anywhere 是 Rails 3.x 应用程序的解决方案,但我正在使用 Rails 2.3.11
想法?
【问题讨论】:
标签: ruby-on-rails actioncontroller actionviewhelper