2017-07-25 43 views
0

有一段时间没有使用Rails,只是克隆了一个项目,试图与数据库一起工作,但我得到这个未初始化的常量错误,我似乎无法弄清楚为什么。我捆绑安装,创建数据库,迁移和种子一些文件,但我似乎无法找到问题的根源。这是一个不小的工程,它似乎是工作,当我用它精细回...任何帮助,将不胜感激它...Ruby on Rails - NameError:未初始化的常量用户

这里是我的Gemfile:

source 'https://rubygems.org' 

git_source(:github) do |repo_name| 
    repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 
    "https://github.com/#{repo_name}.git" 
end 

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '~> 5.1.1' 
gem 'httparty' 
# Use postgresql as the database for Active Record 
gem 'pg', '~> 0.18' 
# Use Puma as the app server 
gem 'puma', '~> 3.7' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.2' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.5' 
# Use Redis adapter to run Action Cable in production 
# gem 'redis', '~> 3.0' 
# Use ActiveModel has_secure_password 
gem 'bcrypt', '~> 3.1.7' 
# gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt' 
gem 'semantic-ui-sass', git: 'https://github.com/doabit/semantic-ui-sass.git' 
# gem 'capistrano-rails', group: :development 
gem 'pg_search' 

group :development, :test do 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 
    gem 'faker' 
end 

group :development do 
    # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 
    gem 'web-console', '>= 3.3.0' 
    gem 'listen', '>= 3.0.5', '< 3.2' 
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
    gem 'spring-watcher-listen', '~> 2.0.0' 
end 
gem 'rails_12factor', group: :production 
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 

而这里的用户模式:

class User < ApplicationRecord 
    validates :first_name, :last_name, :presence => true 
    validates :username, :email, :presence => true, :uniqueness => true 
    has_many :messages 
    has_many :posts, :foreign_key => :creator_id 
    has_many :apprenticeships, :foreign_key => :requestor_id 
    has_many :skills, through: :posts 

    has_secure_password 

    def full_name 
    "#{self.first_name} #{self.last_name}" 
    end 

end 

我也曾尝试检查,如果表用ActiveRecord::Base.connection.tables创建的,但我仍然得到NameError: uninitialized constant ActiveRecord

+0

所以我可以玩数据库,如果我使用'rails console --sandbox',是不是有一种方式可以直接使用'irb'或'pry'访问数据库? – user7496931

+0

耶稣......轨道控制台......忽略我的每个人。我很惭愧。 – user7496931

回答

2

使用在Ruby on Rails项目中工作时,不使用irbpry。 Rails有一个复杂的引导过程,它的许多类都被延迟加载。像irbpry这样的通用交互式控制台不会执行加载Rails应用程序所需的引导,但rails console会。

相关问题