I’m having an issue performing a query for only objects that are active. I do not have an active column in the database, instead, on a model Game, I have the following method:
def complete?
self.winner ? true : false
end
That way if a Game has a Winner, #complete? will return true. I want to query for all Games that would return false for this method, is there a way to do this with ActiveRecord? Right now in my controller I’m simply calling @games = Game.all, and then in my partial rendering games like:
<% unless game.complete? %>
yada yada
<% end %>
This seems kind of hacky, and would require me to write a different partial if I want to display “completed” games. Anyway, I was wondering if there is a way in the controller to only assign objects that would return true/false from a model method?
What about a fast and easy class method?
Then call
Game.completed_games. You can make one for incomplete games too. You can make that method one line too, but I broke it up so you can see exactly what’s going on.