【发布时间】:2010-03-17 16:55:23
【问题描述】:
我想使用一个自定义模板文件,它应该在 Rails 金属代码中使用基本布局文件 (app/view/layouts/application.html.erb)。有人可以给我一些提示,我需要什么或如何做到这一点?
【问题讨论】:
标签: ruby-on-rails ruby
我想使用一个自定义模板文件,它应该在 Rails 金属代码中使用基本布局文件 (app/view/layouts/application.html.erb)。有人可以给我一些提示,我需要什么或如何做到这一点?
【问题讨论】:
标签: ruby-on-rails ruby
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
【讨论】: