0

我得到了以下红宝石示例:

require 'tilt'
data = { "site_link" => "http://www.example.com", "title" => "example"}
template = Tilt.new('../templates/test.erb', :default_encoding => 'UTF-8')
output = template.render(data)

puts output

这是 test.erb 文件:

This should be a link - <%= site_link %>

我找不到合适的语法来从数据哈希中获取值到模板中。

4

1 回答 1

1

好的,看起来我需要指定倾斜数据是哈希。正确的代码是:

output = template.render(Hash,data)
于 2015-11-25T08:57:55.450 回答