resource_t嵌套资源的问题:“无法将符号转换为整数”

时间:2011-06-14 08:58:32

标签: ruby-on-rails ruby-on-rails-3

我在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"}

1 个答案:

答案 0 :(得分:1)

ruby​​ 1.9.2中ruby的Array#to_s方法更改引起的问题 - resource_this期望[:posts].to_s出现为"posts"但在ruby 1.9.2中它出现为{{1}好像你已经完成了Array#inspect。这搞砸了resource_this如何解决父类的类名。

你可以通过说

来解决这个问题
"[:posts]"

而不是

resource_this :nested => :posts

或者您可以使用

中我的分叉版本的resource_this

https://github.com/toastkid/resource_this

:)