Adam Adam - 7 months ago 31
Ruby Question

selecting certain users in rails

I'm writing a zombie survival app, and I'm trying to select all my users marked "alive" where :alive is a boolean.
I was writing a private method in my users controller but can't get the ruby right, does anyone have a pointer?

def get_alive
@holder = ( {|user| user})
@user = @holder.each {|i| if i.alive @user << i}



Use a scope to find all alive users.

class User < ActiveRecord::Base
  scope :alive, where(:alive => true)
  # ... the rest of your model ...

Then you can do this:

@alive_users = User.alive