html - 如何在 html 中使用 ruby​​ 输出?

标签 html ruby

我有一个 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/

相关文章:

javascript - 使用多个超链接作为提交和输入

jquery - Bootstrap INSPINIA 可折叠导航栏

html - 双背景图像顶部和底部

ruby - Grape 中的通配符路线

javascript - jquery 显示/隐藏 block 中的 Ruby 变量

html - Bootstrap 中单个元素 form-group 的作用是什么?

html - 导航栏不适合顶部

ruby - 有没有办法直接运行 ruby 鞋应用程序?

javascript - 设置动态嵌套表单名称和 ID 属性

ruby - 命名 Ruby 方法