Question

I have a hash containing key value pairs, and I'm trying to use a ternary if but it doesn't seem to work.

<%= @positions.key? 'dashboard' %> # => true

<%= @positions.key? 'dashboard' ? 'true text' : 'no text' %> # => false

Am I not using the correct code? If this doesn't work is there a way to check if a hash key exists using a ternary if condition?

Was it helpful?

Solution

Add parenthesis around parameter:

<%= @positions.key?('dashboard') ? 'true text' : 'no text' %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top