内容简介:感谢大家!翻译自: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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Hello World
Hannah Fry / W. W. Norton Company / 2018-9 / GBP 17.99
A look inside the algorithms that are shaping our lives and the dilemmas they bring with them. If you were accused of a crime, who would you rather decide your sentence—a mathematically consistent ......一起来看看 《Hello World》 这本书的介绍吧!