如果我呈现 html,我会将 html 发送到浏览器,效果很好。但是,在模块或类中调用时如何获得路由的响应(html)。
我需要这样做,因为我要将文档发送到 DocRaptor,而不是将标记/html 存储在数据库列中,我想存储记录 ID 并在作业执行时创建标记。
一个可能的解决方案是使用 Ruby 的 HTTP 库、Httparty 或 wget 或其他东西,然后打开路由并使用 response.body。在这样做之前,我想我应该四处打听。
谢谢!
-- 更新--
这是我最终得到的东西:
快速提示 - 如果有人这样做并且需要他们的帮助方法,您需要使用 ApplicationHelper 扩展 AV:
这是我最终做的事情:
av = ActionView::Base.new()
av.view_paths = ActionController::Base.view_paths
av.extend ApplicationHelper #or any other helpers your template may need
body = av.render(:template => "orders/receipt.html.erb",:locals => {:order => order})
链接: http://www.rigelgroupllc.com/blog/2011/09/22/render-rails3-views-outside-of-your-controllers/
最佳答案
检查这个问题,它包含答案中可能需要的代码:
关于ruby - 稍后通过 delayed_job 呈现 View 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16972797/