<分区>
Possible Duplicate:
Checking if a variable is defined in Ruby
使用 Tilt 的模板 render
方法,我传入
#... t setup ...
t.render(self, { :a => 'test', :b => 'again' })
在我的 template.erb
<%= a %>
<%= b %>
假设我删除了 :b
从我传递给模板的散列。渲染将失败,因为 :b
未定义。
在 PHP 中,我可以:
<?= isset($foo) ? $foo : '' ?>
是否有任何干净的方法(在 ruby/erb 中)来“回显 if”?
我试过了 <%= b.nil? ? b : '' %>
但这显然是错误的.. 任何帮助将不胜感激