Bulk suspend users based on criteria

If you would like to use the rails console to bulk suspend users, something like this should do the trick:

suspend_till = DateTime.new(2057,1,1)
users = User.where(last_seen_at: nil, id: 1..Float::INFINITY, admin: false)
users.each do |u|
  u.suspended_till = suspend_till
  u.suspended_at = DateTime.now
  u.save!
end
5 Likes