Erb与Sinatra在ruby

栏目: Ruby · 发布时间: 7年前

内容简介:感谢大家!翻译自:https://stackoverflow.com/questions/2568266/erb-with-sinatra-in-ruby

所以我有一个我用sinatra构建的网络服务器,其内容如下:

set :variable,"value"
get '/' do
  erb :index
end

当然,views / index.erb中的模板看起来像这样:

<html>
<!-- etc -->
  <ul>
  <% my_array.each do |thing| %>
  <%="Something: #{thing}, variable from sinatra: #{settings.variable}"%>
  <% end %>
  </ul>
</html>

如果您尝试运行这样的代码,您会注意到您无法从erb模板内部访问sinatra的设置变量.任何想法如何在保持简洁的同时实现这一目标?

提前致谢!

感谢大家!

翻译自:https://stackoverflow.com/questions/2568266/erb-with-sinatra-in-ruby


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms in C (Computer Science Series)

Algorithms in C (Computer Science Series)

Robert Sedgewick / Addison-Wesley Professional / 1990-01-11 / USD 59.99

This new version of the best-selling book, Algorithms, SecondEdition, provides a comprehensive collection of algorithmsimplemented in C. A variety of algorithms are described in eachofthe following ar......一起来看看 《Algorithms in C (Computer Science Series)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具