我正在开发用于Comatose的Rails 3.2.8引擎,用于开发Rails引擎的一些实践。我遇到了一个奇怪的问题,我想知道是否还有其他人遇到过这个问题。主要问题是 ActionDispatch :: Routing :: RouteSet#eval_block 。当方法调用Mapper.new时,我得到“错误的参数数量(1表示0)”的例外。这是当前的定义:
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
从调试器断点,Mapper是ActionDispatch :: Routing :: RouteSet :: Mapper,而不是ActionDispatch :: Routing :: Mapper。但是,我无法在任何地方找到ActionDispatch :: Routing :: RouteSet :: Mapper。
我不知道是否有一些动态的Ruby / Rails Magic正在发生,其中Mapper实际上是由一些gem在RouteSet中定义的。我似乎无法追踪到这一点,而且我已经在整个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
我在其他项目之前从未遇到过这个错误。这是我在框架中测试Engine的第一次尝试,但我之前在其他项目中使用过Engines。 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
答案 0 :(得分:0)
我遇到了同样的问题。
在我的情况下,它是由一个旧插件(savage-beast)引起的,它有以下代码:
class ActionController::Routing::RouteSet::Mapper
def from_plugin(name)
eval File.read(File.join(RAILS_ROOT, "vendor/plugins/#{name}/routes.rb"))
end
end
导致了这个问题。也许这可以帮助。 我认为问题是因为旧的RAILS_ROOT而不是Rails.root