【问题标题】:How to render in rails metal?如何在铁轨金属中渲染?
【发布时间】:2010-03-17 16:55:23
【问题描述】:

我想使用一个自定义模板文件,它应该在 Rails 金属代码中使用基本布局文件 (app/view/layouts/application.html.erb)。有人可以给我一些提示,我需要什么或如何做到这一点?

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:
    require 'erb'
    class Poller # in metal
      def self.call(env)
        # can find abs path using File.dirname(__FILE__) / .. / app / ...
        view = IO.read(`/absolute/path/app/view/layouts/application.html.erb`)
        template = ERB.new(view)
        body = template.result(binding)
        [200, {"Content-Type" => "text/html"}, body]
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2016-03-06
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      相关资源
      最近更新 更多