我今天嘗試創建一個新的Rails應用程序,並且該應用程序的行爲好像ActiveRecord根本不存在。Rails 4.2.3`method_missing':未定義的方法`active_record'
我創建的應用程序有:
rails new myapp --database=mysql
當運行耙分貝:創建,我得到:
rake aborted!
NoMethodError: undefined method `active_record' for #<Rails::Application::Configuration:0x007faad08b3058>
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/railtie/configuration.rb:95:in `method_missing'
/Users/richard/Dropbox/Development/myapp/config/application.rb:24:in `<class:Application>'
/Users/richard/Dropbox/Development/myapp/config/application.rb:10:in `<module:Myapp>'
/Users/richard/Dropbox/Development/myapp/config/application.rb:9:in `<top (required)>'
/Users/richard/Dropbox/Development/myapp/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
事實上,如果我註釋掉這些行,然後運行rake -T :
...
rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_c...
rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_commen...
rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides (options: TEM...
rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=t...
rake middleware
...
沒有rake db:* tasks at all!
我有一堆其他的Rails應用程序,從Rails 3.x到Rails 4.2.0,他們都工作正常。這就是今天創建的這個應用程序(以及任何新的應用程序),它顯示了這種行爲。
運行OSX 10.10,Ruby 2.0.0,完全備份Gemfile。
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 Myapp
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
另一種看法 - 回滾到Rails 4.1.0似乎很好地工作。 4.2.x仍然不起作用。 –
你可以發佈你的'config/application.rb'文件嗎? – BroiSatse
在原始問題中添加了application.rb。 –