Better way to write @instances.count > 0

ruby, ruby-on-rails

Solution

You probably want ActiveRecord's `any?`

http://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-any-3F

<% if @states.any? %>
    Do stuff here if @states has at least one result
<% end %>

Problem

I have this code: ``` <% if @states.count > 0 %> # @states is an active record collection ``` I just feel like there should be a better way to write this. I am looking for something like: ``` <% if @states.not_empty? %> ``` I realize this is tiny change but it would be a welcome cleanup.

Original source