参数错误递归数组连接



在控制器或模板中调用方法"polymorphic_url",数组作为参数,例如:

polymorphic_url([@agency, @agency.divisions.first])

导致名为"递归数组连接"的参数错误异常。有什么建议吗?

我可以使用任何模型重现此异常:

@e = Estate.where(:booklets => {'$exists' => true}).first
@b = @e.booklets.first
polymorphic_url [@e,@b]

导轨 3.2.3, 3.2.4, 3.2.5

红宝石 1.9.2, 1.9.3

您可以使用包含对自身的引用的数组创建错误:

a = []
a<<a
a.join #ArgumentError: recursive array join

我在这里猜测,但如果divisions指向与@agencie相同的数组(例如,机构是它自己的部门),我可以想象发生类似上面的事情。可能它与更新无关,但与数据无关。

我相信

你在滥用它。根据APIDock,以下是一些polymorphic_url使用的例子:

# calls post_url(post)
polymorphic_url(post) # => "http://example.com/posts/1"
polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
polymorphic_url(Comment) # => "http://example.com/comments"

所以也许你应该使用:

polymorphic_url([@agency, @division])

我通过强制应用程序使用 bson '1.6.2' 来解决此问题https://github.com/mongoid/mongoid/issues/2069

最新更新