简体   繁体   English

运行Rails服务器时出现NameError

[英]NameError when I run my rails server

I ran the command rails server -p 8000 in the console to start my rails app, and I went to localhost:8000 in my browser, but I got an error saying something went wrong. 我在控制台中运行了rails server -p 8000命令来启动我的Rails应用程序,然后我在浏览器中转到了localhost:8000,但是出现了一个错误,表明出现了问题。 I checked my console, and I saw this: 我检查了控制台,然后看到了:

Started GET "/" for 127.0.0.1 at 2015-08-15 14:21:23 -0400

NameError (uninitialized constant ActiveModel::Validations::PresenceValidator):
  activerecord (4.2.3) lib/active_record/validations/presence.rb:3:in `<module:Validations>'
  activerecord (4.2.3) lib/active_record/validations/presence.rb:2:in `<module:ActiveRecord>'
  activerecord (4.2.3) lib/active_record/validations/presence.rb:1:in `<top (required)>'
  activerecord (4.2.3) lib/active_record/validations.rb:90:in `<top (required)>'
  activerecord (4.2.3) lib/active_record/base.rb:294:in `<class:Base>'
  activerecord (4.2.3) lib/active_record/base.rb:269:in `<module:ActiveRecord>'
  activerecord (4.2.3) lib/active_record/base.rb:26:in `<top (required)>'
  activerecord (4.2.3) lib/active_record/migration.rb:383:in `connection'
  activerecord (4.2.3) lib/active_record/migration.rb:370:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.3) lib/rails/engine.rb:518:in `call'
  railties (4.2.3) lib/rails/application.rb:165:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

I updated all of my gems yesterday, including rails, so I'm thinking it has something to do with that. 我昨天更新了我所有的宝石,包括铁轨,所以我认为这与它有关。 Is there something I did wrong when I updated all of the gems? 更新所有宝石时,我做错了什么吗? I ran the command, and then I updated the Gemfile, but did I miss anything? 我运行了命令,然后更新了Gemfile,但是我错过了什么吗? (Let me know if you want me to put the Gemfile in here as well) Here's my Gemfile (让我知道您是否也希望将Gemfile放在这里)这是我的Gemfile

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]

# Scans for vulnerabilities
gem 'brakeman',  '~> 3.0.5'

gem 'dawnscanner', '~> 1.3.5'

You have to require the whole of active_model since it uses autoload to "lazily require" classes as needed. 您必须需要整个active_model,因为它会根据需要使用自动加载功能来“懒惰地要求”类。

The following code works fine: 以下代码可以正常工作:

require 'active_model'


class Person
  include ActiveModel::Validations
end

I think I figured out the problem. 我想我已经解决了问题。 I made a new app, without the two gems, and it worked. 我创建了一个新的应用程序,没有两块宝石,并且运行正常。 I went to my app and took out one of the gems ( dawnscanner ) and it worked. 我去了我的应用程序,取出其中一颗宝石( dawnscanner ),它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行命令Rails服务器时出现NameError - Getting a NameError when I run the command rails server 我在localhost上运行服务器时出现问题(ruby on rails) - Problem when I run my server on localhost (ruby on rails) 当我运行Rails Server时,它会复制我的所有文件 - When I run rails server, it duplicates all my files 当我在Unicorn服务器上运行时,Websockets在我的Rails应用程序中不起作用,但在瘦服务器上运行 - Websockets not working in my Rails app when I run on Unicorn server, but works on a Thin server Rails服务器将无法运行-未初始化的常量使用(NameError) - Rails server won't run - uninitialized constant use (NameError) 手动运行服务器时,为什么不能连接到Heroku Rails应用程序? - Why can't I connect to my Heroku rails app when I run the server manually? 启动Rails服务器时未初始化的常量版本(NameError) - Uninitialized constant Version (NameError) when starting Rails server 启动Rails服务器时未初始化的常量Formtastic :: SemanticFormBuilder(NameError) - uninitialized constant Formtastic::SemanticFormBuilder (NameError) when starting rails server 将我的应用程序升级到rails 3.1.1时获取NameError - Getting a NameError when upgrading my app to rails 3.1.1 尝试在我的 Rails 6 controller 中包含问题时面临 NameError - Facing the NameError when trying to include concerns in my rails 6 controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM