我有一个包含键值对的哈希,我试图使用三元组,但它似乎没有用。
<%= @positions.key? 'dashboard' %> # => true
<%= @positions.key? 'dashboard' ? 'true text' : 'no text' %> # => false
我没有使用正确的代码吗?如果这不起作用,有没有办法检查是否存在使用三元if条件的散列键?
答案 0 :(得分:3)
在参数:
周围添加括号<%= @positions.key?('dashboard') ? 'true text' : 'no text' %>