我正在开发一个Rails 3.2.8 Engine for Comatose,用于开发Rails引擎的一些练习。我遇到了一个奇怪的问题,我想知道是否有其他人也遇到了它。主要问题在于ActionDispatch :: Routing :: RouteSet#eval_block。我得到的“错误的参数数目(1 0)时,方法调用Mapper.new异常下面是当前定义:Rails 3.2.8:ActionDispatch :: Routing :: RouteSet :: Mapper,它存在吗?
def eval_block(block)
if block.arity == 1
raise "You are using the old router DSL which has been removed in Rails 3.1. " <<
"Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/"
end
mapper = Mapper.new(self)
if default_scope
mapper.with_default_scope(default_scope, &block)
else
mapper.instance_exec(&block)
end
end
来自调试断点,映射是ActionDispatch ::路由:: RouteSet: :Mapper,而不是ActionDispatch :: Routing :: Mapper。但是我找不到在任何地方定义的ActionDispatch :: Routing :: RouteSet :: Mapper。
我不知道是否有一些动态的Ruby/Rails Magic正在发生其中Mapper实际上已经在RouteSet里被一些gem定义了,我似乎无法跟踪它,并且我已经在整个gemset中搜索了“Mapper”,但找不到任何东西。
我实际上不得不在我的代码中使用test/dummy/config/initializer中的初始化工具创建工作,以便Mapper完全合格。
::ActionDispatch::Routing::RouteSet.class_eval do
def eval_block(block)
if block.arity == 1
raise "You are using the old router DSL which has been removed in Rails 3.1. " <<
"Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/"
end
mapper = ::ActionDispatch::Routing::Mapper.new(self)
if default_scopeSo,
mapper.with_default_scope(default_scope, &block)
else
mapper.instance_exec(&block)
end
end
end
我从来没有在其他项目中遇到过这个错误。这是我在框架内测试引擎的第一次尝试,但我之前在其他项目中使用过引擎。代码在Rails 3.2.7中看起来也是一样的。
是否有其他人遇到问题,或者我在做一些完全错误的事情?我使用Ruby 1.9.3-p194,Rails 3.2.8,当然还有许多宝石。我正在使用完全更新的Ubuntu 12.04,并使用RVM。从捆绑的宝石说我使用的是如下:
Using rake (0.9.2.2)
Using RedCloth (4.2.9)
Using i18n (0.6.1)
Using multi_json (1.3.6)
Using activesupport (3.2.8)
Using builder (3.0.1)
Using activemodel (3.2.8)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.3)
Using actionpack (3.2.8)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.4)
Using actionmailer (3.2.8)
Using arel (3.0.2)
Using tzinfo (0.3.33)
Using activerecord (3.2.8)
Using activeresource (3.2.8)
Using acts_as_list (0.1.8)
Using acts_as_tree (1.1.0)
Using acts_as_versioned (0.2.3)
Using bundler (1.2.0)
Using cocaine (0.3.0)
Using columnize (0.3.6)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Using rdoc (3.12)
Using thor (0.16.0)
Using railties (3.2.8)
Using jquery-rails (2.1.1)
Using rails (3.2.8)
Using comatose (0.0.1) from source at .
Using daemons (1.1.9)
Using debugger-ruby_core_source (1.1.3)
Using debugger-linecache (1.1.2)
Using debugger (1.2.0)
Using eventmachine (0.12.10)
Using liquid (2.4.1)
Using paperclip (3.1.4)
Using responds_to_parent (1.1.0)
Using sqlite3 (1.3.6)
Using test-unit (2.5.2)
Using thin (1.4.1)
这是一个问题带来了Rails的,如果是这样,我在哪里做呢?这是Ruby的误解范围规则我不理解?比如,为什么Mapper在ActionDispatch :: Routing :: RouteSet模块中引用一个不存在的类,而不是引用ActionDispatch :: Routing模块中的Mapper类?
感谢, -polar