当我在新创建的rails项目上运行rails server
时,我一直有以下错误消息。我是通过运行命令rails new toy_app
创建的。
请指导我如何解决我的问题。我有另一个rails项目,我可以运行rails server
。在我的新项目中是不可能的。
错误消息
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/railtie/configuration.rb:95:in
`method_missing': undefined method `active_record' for
#<Rails::Application::Configuration:0x007f9413116e40> (NoMethodError) from /Users/judobear/toy_app/config/application.rb:24:in
`<class:Application>' from
/Users/judobear/toy_app/config/application.rb:10:in `<module:ToyApp>'
from /Users/judobear/toy_app/config/application.rb:9:in `<top
(required)>' from
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in
`require' from
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in
`block in server' from
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in
`tap' from
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in
`server' from
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in
`run_command!' from
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands.rb:17:in
`<top (required)>' from /Users/judobear/toy_app/bin/rails:8:in
`require' from /Users/judobear/toy_app/bin/rails:8:in `<top
(required)>' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in
`load' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in
`call' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client/command.rb:7:in
`call' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client.rb:26:in
`run' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/bin/spring:48:in `<top
(required)>' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in
`load' from
/Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in
`<top (required)>' from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in
`require' from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in
`require' from /Users/judobear/toy_app/bin/spring:13:in `<top
(required)>' from bin/rails:3:in `load' from bin/rails:3:in `<main>'
的Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
application.rb中
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Toyapp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
答案 0 :(得分:3)
在我自己遇到同样的问题后,另一位用户将其追溯到了Arel gem的6.0.1版本的bug,该版本于昨天被提出并随后修复:
Rails 4.2.3 `method_missing': undefined method `active_record'
如果您今天运行“捆绑更新”然后继续,您的应用程序现在应该没问题。
HTH。
答案 1 :(得分:2)
尝试在Gemfile中更改回Rails 4.1.0 - 不太理想,但我今天遇到完全相同的问题,这很有效。
我猜这是Rails 4.2.x的一个错误(只是一个猜测)。
编辑:4.1.12也适用(4.1.x中的最新版本)