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