我在控制台中运行命令rails server -p 8000
以启动我的rails应用程序,然后我在浏览器中访问了localhost:8000,但是我收到错误消息说出错了。我检查了我的控制台,我看到了这个:
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'
我昨天更新了所有宝石,包括rails,所以我认为它与它有关。当我更新所有宝石时,有什么我做错了吗?我运行了命令,然后我更新了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'
答案 0 :(得分:2)
你必须要求整个active_model,因为它使用自动加载到&#34; lazily require&#34;根据需要上课。
以下代码可以正常使用:
require 'active_model'
class Person
include ActiveModel::Validations
end
答案 1 :(得分:0)
我想我弄明白了这个问题。我做了一个新的应用程序,没有两个宝石,它工作。我去了我的应用程序并取出了一个宝石(dawnscanner
)并且它有效。