Tuesday, 15 January 2013

Accessing database from rails console -



Accessing database from rails console -

when open rails console, running ./script/console (script folder contains console file) , input in console users.find(:all) , message

'nameerror: uninitialized constant user (irb):1 '

i have similar message each time run commnad in console (knowing didn't connect irb). googled , saw similar issues asked on stack, , didn't satisfactory answer. has thought ?

eidt 1 : don't konow if usefull, here's suggested posted user model class

require "digest/sha1" require_dependency "event" class user < activerecord::base include urllinting include gitorious::authorization has_many :projects has_many :memberships, :dependent => :destroy has_many :groups, :through => :memberships has_many :repositories, :as => :owner, :conditions => ["kind != ?", repository::kind_wiki], :dependent => :destroy has_many :cloneable_repositories, :class_name => "repository", :conditions => ["kind != ?", repository::kind_tracking_repo] has_many :committerships, :as => :committer, :dependent => :destroy has_many :commit_repositories, :through => :committerships, :source => :repository, :conditions => ["repositories.kind not in (?)", repository::kinds_internal_repo] has_many :ssh_keys, :order => "id desc", :dependent => :destroy has_many :comments has_many :email_aliases, :class_name => "email", :dependent => :destroy has_many :events, :order => "events.created_at asc", :dependent => :destroy has_many :events_as_target, :class_name => "event", :as => :target has_many :favorites, :dependent => :destroy has_many :feed_items, :foreign_key => "watcher_id" has_many :content_memberships, :as => :member # virtual attribute unencrypted password attr_accessor :password, :current_password attr_protected :login, :is_admin, :password, :current_password # new users little more strict existing ones. username_format = /[a-z0-9\-_\.]+/i.freeze username_format_on_create = /[a-z0-9\-]+/.freeze validates_presence_of :login, :email, :if => :password_required? validates_format_of :login, :with => /^#{username_format_on_create}$/i, :on => :create validates_format_of :login, :with => /^#{username_format}$/i, :on => :update validates_format_of :email, :with => email::format validates_presence_of :password, :if => :password_required? validates_presence_of :password_confirmation, :if => :password_required? validates_length_of :password, :within => 4..40, :if => :password_required? validates_confirmation_of :password, :if => :password_required? validates_length_of :login, :within => 3..40 validates_length_of :email, :within => 3..100 validates_uniqueness_of :login, :email, :case_sensitive => false validates_acceptance_of :terms_of_use, :on => :create, :allow_nil => false validates_format_of :avatar_file_name, :with => /\.(jpe?g|gif|png|bmp|svg|ico)$/i, :allow_blank => 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 => :pending state :terms_accepted event :accept_terms transition :pending => :terms_accepted end end

edit 2 : when run console have omitted error messages (but console loads)

/var/www/gitorious/config/environment.rb:25:runtimeerror: config/gitorious.yml not have entry current rails environment. please consult config/gitorious.sample.yml 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

assuming have user model defined below: app/models/user.rb

class user < activerecord::base #your things end

use model name (i.e) user not users:

user.find(:all) or user.all # display user records

ruby-on-rails console

No comments:

Post a Comment