Class: CreateAdminUser

Inherits:
Object show all
Defined in:
app/metal/create_admin_user.rb

Overview

note: we’re not returning 404 in the usuaul sense - it actually just tells rails to continue metal chain

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/metal/create_admin_user.rb', line 7

def self.call(env)                
  if env["PATH_INFO"] =~ /^\/users/ or @admin_defined or not User.table_exists?
    @status = [404, {"Content-Type" => "text/html"}, "Not Found"]
  else
    @admin_defined = User.first(:include => :roles, :conditions => ["roles.name = 'admin'"])
    @status = [404, {"Content-Type" => "text/html"}, "Not Found"] if @admin_defined
  end
  # redirect to user creation screen
  return @status || [302, {'Location'=> '/users/new' }, []]
ensure
  # Release the connections back to the pool.
  ActiveRecord::Base.clear_active_connections!
end