title: Accessing database from rails console
body: <p>When I open my rails console, running ./script/console (script folder contains a console file) , I input in the console Users.find(:all) and I get this message</p>
  
  <pre><code>'NameError: uninitialized constant User
      from (irb):1
  '
  </code></pre>
  
  <p>I have similar message each time I run a commnad in the console (knowing I didn't connect by irb). I googled it and saw some similar issues that were asked on stack, and I didn't get any satisfactory answer. Someone has an idea ?</p>
  
  <p>Eidt 1 : I don't konow if it is usefull, but here's as suggested to be posted the user model class </p>
  
  <pre><code>require "digest/sha1"
  require_dependency "event"
  
  class User &lt; ActiveRecord::Base
    include UrlLinting
    include Gitorious::Authorization
  
    has_many :projects
    has_many :memberships, :dependent =&gt; :destroy
    has_many :groups, :through =&gt; :memberships
    has_many :repositories, :as =&gt; :owner, :conditions =&gt; ["kind != ?", Repository::KIND_WIKI],
      :dependent =&gt; :destroy
    has_many :cloneable_repositories, :class_name =&gt; "Repository",
       :conditions =&gt; ["kind != ?", Repository::KIND_TRACKING_REPO]
    has_many :committerships, :as =&gt; :committer, :dependent =&gt; :destroy
    has_many :commit_repositories, :through =&gt; :committerships, :source =&gt; :repository,
    :conditions =&gt; ["repositories.kind NOT IN (?)", Repository::KINDS_INTERNAL_REPO]
    has_many :ssh_keys, :order =&gt; "id desc", :dependent =&gt; :destroy
    has_many :comments
    has_many :email_aliases, :class_name =&gt; "Email", :dependent =&gt; :destroy
    has_many :events, :order =&gt; "events.created_at asc", :dependent =&gt; :destroy
    has_many :events_as_target, :class_name =&gt; "Event", :as =&gt; :target
    has_many :favorites, :dependent =&gt; :destroy
    has_many :feed_items, :foreign_key =&gt; "watcher_id"
    has_many :content_memberships, :as =&gt; :member
  
    # Virtual attribute for the unencrypted password
    attr_accessor :password, :current_password
  
    attr_protected :login, :is_admin, :password, :current_password
  
    # For new users we are a little more strict than for existing ones.
    USERNAME_FORMAT = /[a-z0-9\-_\.]+/i.freeze
    USERNAME_FORMAT_ON_CREATE = /[a-z0-9\-]+/.freeze
    validates_presence_of     :login, :email,               :if =&gt; :password_required?
    validates_format_of       :login, :with =&gt; /^#{USERNAME_FORMAT_ON_CREATE}$/i, :on =&gt; :create
    validates_format_of       :login, :with =&gt; /^#{USERNAME_FORMAT}$/i, :on =&gt; :update
    validates_format_of       :email, :with =&gt; Email::FORMAT
    validates_presence_of     :password,                   :if =&gt; :password_required?
    validates_presence_of     :password_confirmation,      :if =&gt; :password_required?
    validates_length_of       :password, :within =&gt; 4..40, :if =&gt; :password_required?
    validates_confirmation_of :password,                   :if =&gt; :password_required?
    validates_length_of       :login,    :within =&gt; 3..40
    validates_length_of       :email,    :within =&gt; 3..100
    validates_uniqueness_of   :login, :email, :case_sensitive =&gt; false
    validates_acceptance_of :terms_of_use, :on =&gt; :create, :allow_nil =&gt; false
    validates_format_of     :avatar_file_name, :with =&gt; /\.(jpe?g|gif|png|bmp|svg|ico)$/i, :allow_blank =&gt; true
  
    before_save :encrypt_password
    before_create :make_activation_code
    before_validation :lint_identity_url, :downcase_login
    after_save :expire_avatar_email_caches_if_avatar_was_changed
    after_destroy :expire_avatar_email_caches
  
    state_machine :aasm_state, :initial =&gt; :pending do
      state :terms_accepted
  
      event :accept_terms do
        transition :pending =&gt; :terms_accepted
      end
  
    end
  </code></pre>
  
  <p>Edit 2 : when I run my console I have omitted some error messages (but the console loads) </p>
  
  <pre><code> /var/www/gitorious/config/environment.rb:25:RuntimeError: Your config/gitorious.yml does not have an entry for your current Rails environment. Please consult config/gitorious.sample.yml for instructions.
  /usr/lib/ruby/gems/1.8/gems/rails-2.3.14/lib/rails/backtrace_cleaner.rb:2:NameError: uninitialized constant ActiveSupport::BacktraceCleaner
  /usr/lib/ruby/gems/1.8/gems/rails-2.3.14/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController
  </code></pre>