我有一个 ruby 程序可以从 api 获取 json 并将值与它分开并显示它。 我需要做的是以 html 形式呈现输出。我如何从 ruby 中获取值并将其传递给 html,以便我可以使用该值。
最佳答案
您可以使用 tilt gem
例如模板foo.html.haml
:
!!! 5
%html
%head
%title Rotten Potatoes!
%body
%h1.title Rotten Potatoes!
Hey = yield!
然后将名字传递给templete:
template = Tilt::ERBTemplate.new('foo.html.haml')
output = template.render { 'Joe' } # => html code with phrase 'Hey Joe!'
关于html - 如何在 html 中使用 ruby 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11322297/