Question

I have such code in my view:

<% @items.each do |item| %>
<tr<%= raw(item.presence ? '' : ' class="opaque"') %>>
...
<td><%= item.presence ? 'Yes' : 'No' %></td>
</tr>
<% end %>

this is request in controller:

@items = Item.where(:type_id => @type.id).order('brand ASC, name ASC').limit(limit).offset((@page-1)*limit)

'presence' field is just bool, nil in first item Despite the fact that the first acquired item's presence field is nil, it doesn't return class attr for the first row (like it is not nil or true), but the second check returns right value ('No'). In the other rows with false or nil values it returns right values in both checks. Is it a bug, or I'm doing smth wrong?

Rails 3.0.0, Postgres 8.4

Was it helpful?

Solution

does adding the ? to presence help...

<% @items.each do |item| %>
<tr<%= raw(item.presence? ? '' : ' class="opaque"') %>>
...
<td><%= item.presence? ? 'Yes' : 'No' %></td>
</tr>
<% end %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top