Ruby Check if at least one element from collection meets condition
<p>My models have the following relation</p>

<pre><code>class User &lt; ActiveRecord::Base
  has_many :controllers
end

class Controller &lt; ActiveRecord::Base
  belongs_to :user
end
</code></pre>

<p><code>Controller</code> has a boolean called <code>is_active</code>.</p>

<p>I would like to raise an exception if all controller objects which belong to a specific user object are <code>is_active</code> false.</p>

<p>Unfortunately i struggle  putting this sentence into code. </p>

<pre><code># if for all controllers is_active false is met, raise exception
# ~&gt;  need to find one controller which is active
array = []
User.find(id).controllers.each do |c|
   array &lt;&lt; c.is_active
end
unless array.include?('true') 
 raise ...
end
</code></pre>

<p>It feels like there is a more <code>rubisch</code> way to write this. </p>