简体   繁体   English

Ruby on Rails`method_missing':未定义的方法`active_record'

[英]Ruby on Rails `method_missing': undefined method `active_record'

I keep having the following error message when i run rails server on my newly created rails project. 当我在新创建的rails项目上运行rails server时,我一直有以下错误消息。 I created it by running the command rails new toy_app . 我是通过运行命令rails new toy_app

Please guide me to how can i solve my problem. 请指导我如何解决我的问题。 I have another rails project and i could run rails server . 我有另一个rails项目,我可以运行rails server Is just not possible in my new project. 在我的新项目中是不可能的。

Error Message 错误信息

/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 的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 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

After having the same issue myself, another user chased it down to a bug with the 6.0.1 version of the Arel gem, which was raised yesterday and subsequently fixed: 在我自己遇到同样的问题后,另一位用户将其追溯到了Arel gem的6.0.1版本的bug,该版本于昨天被提出并随后修复:

Rails 4.2.3 `method_missing': undefined method `active_record' Rails 4.2.3`method_missing':未定义的方法`active_record'

If you run "bundle update" today and then carry on, your app should now be fine. 如果您今天运行“捆绑更新”然后继续,您的应用程序现在应该没问题。

HTH. HTH。

Try changing back to Rails 4.1.0 in your Gemfile - not ideal, but I'm having the exact same issue today and this worked. 尝试在Gemfile中更改回Rails 4.1.0 - 不太理想,但我今天遇到了完全相同的问题,这很有效。

I'm guessing it's a bug with Rails 4.2.x (just a guess). 我猜这是Rails 4.2.x的一个错误(只是一个猜测)。

EDIT: 4.1.12 works as well (latest version in 4.1.x) 编辑:4.1.12也适用(4.1.x中的最新版本)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM