resource_嵌套资源的问题:“无法将Symbol转换为Integer”

问题描述

| 我正在Rails 3.0.7应用程序中使用resource_this插件(https://github.com/jnewland/resource_this)。我以前曾在Rails 2应用程序中使用它,没有问题,但是这次,当我尝试将资源设置为嵌套时:
class EntriesController < ApplicationController
  resource_this :nested => [:reports] #see https://github.com/jnewland/resource_this
end
然后尝试转到其中一个嵌套网址,例如
http://localhost:3000/reports/1/entries
,它会因以下错误而崩溃:
Started GET \"/reports/1/entries\" for 127.0.0.1 at 2011-06-14 09:56:11 +0100

TypeError (can\'t convert Symbol into Integer):
  app/controllers/entries_controller.rb:3:in `<class:EntriesController>\'
  app/controllers/entries_controller.rb:1:in `<top (required)>\'

Rendered /home/max/.rvm/gems/ruby-1.9.2-p0@flamingo/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.1ms)
Rendered /home/max/.rvm/gems/ruby-1.9.2-p0@flamingo/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.1ms)
Rendered /home/max/.rvm/gems/ruby-1.9.2-p0@flamingo/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (18.1ms)
如果我删除嵌套部分,即只有\“ resource_this \”,那么它可以工作,但是我没有自动加载父对象等。我可以自己设置它,但我想找出原因\炸了。其他人看到了吗?堆栈跟踪没有给我太多帮助:/ 谢谢,最大 编辑-顺便说一句,我已经设置了路线,以防有人怀疑这是否是问题所在(我不认为是这样): 从我的routes.rb:
resources :reports do
  resources :entries
end
rake routes
      report_entries GET    /reports/:report_id/entries(.:format)                            {:action=>\"index\",:controller=>\"entries\"}
                     POST   /reports/:report_id/entries(.:format)                            {:action=>\"create\",:controller=>\"entries\"}
    new_report_entry GET    /reports/:report_id/entries/new(.:format)                        {:action=>\"new\",:controller=>\"entries\"}
   edit_report_entry GET    /reports/:report_id/entries/:id/edit(.:format)                   {:action=>\"edit\",:controller=>\"entries\"}
        report_entry GET    /reports/:report_id/entries/:id(.:format)                        {:action=>\"show\",:controller=>\"entries\"}
                     PUT    /reports/:report_id/entries/:id(.:format)                        {:action=>\"update\",:controller=>\"entries\"}
                     DELETE /reports/:report_id/entries/:id(.:format)                        {:action=>\"destroy\",:controller=>\"entries\"}
    

解决方法

        由ruby 1.9.2中ruby的Array#to_s方法的更改引起的问题-resource_this预期ѭ6会以ѭ7的形式出现,但在ruby 1.9.2中它将以ѭ8的形式出现,就好像您已经完成Array#inspect 。这搞砸了resource_this如何计算父级的类名。 您可以说出来
resource_this :nested => :posts
代替
resource_this :nested => [:posts]
或者您可以使用我的resource_this的分支版本 https://github.com/toastkid/resource_this :)     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...