简体   繁体   English

ActiveSupport依赖关系(load_missing_constant)错误-预期…定义(加载错误)

[英]ActiveSupport Dependency (load_missing_constant) Error - Expected … to define (Load Error)

Trying to create an Observer in rails, and getting an error { /active_support/dependencies.rb:503: in 'load_missing_constant': Expected to define (LoadError) } 尝试在rails中创建一个Observer,并得到一个错误{/active_support/dependencies.rb:503:在'load_missing_constant'中:期望定义(LoadError)}

Using Rails 3.2.6, with Ruby 1.9.3-p194 (rvm on Lion). 使用Rails 3.2.6和Ruby 1.9.3-p194(Lion上的rvm)。

Commenting this line in application.rb prevents the error (but also the intended behavior) config.active_record.observers = :page_observer 在application.rb中注释此行可防止错误(但也可防止预期的行为)config.active_record.observers =:page_observer

Full output of 'rails server' command: “ rails server”命令的完整输出:

=> Booting WEBrick
=> Rails 3.2.6 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:503:in 'load_missing_constant': Expected /Users/d/Dropbox/Projects/Postsocial/postsocial/app/models/page.rb to define Page (LoadError)
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in 'block in const_missing'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'const_missing'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:514:in 'load_missing_constant'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in 'block in const_missing'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'const_missing'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/app/models/page_observer.rb:2:in '<class:PageObserver>'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/app/models/page_observer.rb:1:in '<top (required)>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in 'load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in 'block in load_file'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:639:in 'new_constants_in'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:468:in 'load_file'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:353:in 'require_or_load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:502:in 'load_missing_constant'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in 'block in const_missing'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'const_missing'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:229:in 'block in constantize'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:228:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:228:in 'constantize'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/core_ext/string/inflections.rb:54:in 'constantize'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.6/lib/active_model/observing.rb:86:in 'instantiate_observer'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.6/lib/active_model/observing.rb:59:in 'block in instantiate_observers'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.6/lib/active_model/observing.rb:59:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.6/lib/active_model/observing.rb:59:in 'instantiate_observers'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/railtie.rb:117:in 'block (2 levels) in <class:Railtie>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:36:in 'instance_eval'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:36:in 'execute_hook'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:43:in 'block in run_load_hooks'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in 'run_load_hooks'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/base.rb:721:in '<top (required)>'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/app/models/page.rb:1:in '<top (required)>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in 'load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in 'block in load_file'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:639:in 'new_constants_in'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:468:in 'load_file'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:353:in 'require_or_load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:502:in 'load_missing_constant'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in 'block in const_missing'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in 'const_missing'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config/routes.rb:60:in 'block in <top (required)>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in 'instance_exec'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in 'eval_block'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:260:in 'draw'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config/routes.rb:1:in '<top (required)>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in 'load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in 'block in load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in 'load_dependency'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in 'load'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in 'block in load_paths'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in 'load_paths'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:16:in 'reload!'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:26:in 'block in updater'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/file_update_checker.rb:78:in 'call'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/file_update_checker.rb:78:in 'execute'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:27:in 'updater'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:7:in 'execute_if_updated'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/finisher.rb:66:in 'block in <module:Finisher>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:30:in 'instance_exec'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:30:in 'run'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:55:in 'block in run_initializers'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:54:in 'each'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:54:in 'run_initializers'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application.rb:136:in 'initialize!'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in 'method_missing'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config/environment.rb:5:in '<top (required)>'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config.ru:4:in 'require'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config.ru:4:in 'block in <main>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in 'instance_eval'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in 'initialize'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config.ru:1:in 'new'
from /Users/d/Dropbox/Projects/Postsocial/postsocial/config.ru:1:in '<main>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in 'eval'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in 'parse_file'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:200:in 'app'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands/server.rb:46:in 'app'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:301:in 'wrapped_app'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:252:in 'start'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands/server.rb:70:in 'start'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands.rb:55:in 'block in <top (required)>'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands.rb:50:in 'tap'
from /Users/d/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands.rb:50:in '<top (required)>'
from script/rails:6:in 'require'
from script/rails:6:in '<main>'

Content of page_observer.rb page_observer.rb的内容

class PageObserver < ActiveRecord::Observer
end

Content of page.rb page.rb的内容

class Page < ActiveRecord::Base
  attr_accessible :content, :page_style, :slug, :title
end

Any thoughts would be appreciated. 任何想法将不胜感激。

application.rb config.active_record.observers = :page_observer application.rb config.active_record.observers =:page_observer

page_observer.rb page_observer.rb

observe :page

Try initializing your observer in application.rb You also should specify what to observe before your methods. 尝试在application.rb中初始化观察者。您还应该在方法之前指定要观察的内容。

What behavior are you missing? 您缺少什么行为?

暂无
暂无

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

相关问题 RSpec load_missing_constant,期望X定义Y(并且确实如此) - RSpec load_missing_constant, expected X to define Y (and it does) 模块`ActiveSupport :: Dependencies&#39;的未定义方法`load_missing_constant&#39; - undefined method `load_missing_constant' for module `ActiveSupport::Dependencies' radrails开发服务器启动错误:load_missing_constant - radrails dev server startup error: load_missing_constant `load_missing_constant':在自动加载常量 ApplicationRecord (RuntimeError) 时检测到循环依赖 - `load_missing_constant': Circular dependency detected while autoloading constant ApplicationRecord (RuntimeError) `load_missing_constant&#39;:未初始化的常量AuthenticatedTestHelper(NameError) - `load_missing_constant': uninitialized constant AuthenticatedTestHelper (NameError) `load_missing_constant&#39;:未初始化的常量Rails :: Railtie - `load_missing_constant': uninitialized constant Rails::Railtie 尝试在Rails上创建观察者时出现“ load_missing_constant” - 'load_missing_constant' when trying to create an observer on Rails 安装Typus rails插件后的`load_missing_constant&#39; - `load_missing_constant' after installing Typus rails plugin load_missing_constant&#39; 中的块:未初始化的常量 API::V1::Users (NameError) - block in load_missing_constant': uninitialized constant API::V1::Users (NameError) `block in load_missing_constant':启动 Rails 服务器和控制台时未初始化的常量 Pry::Command::ExitAll (NameError) - `block in load_missing_constant': uninitialized constant Pry::Command::ExitAll (NameError) when launching rails server and console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM