4

一段时间以来,我一直在尝试将 has_many 关系添加到我的 ActiveModel::Serializers 中,但我遇到了一堆与它们相关的错误。似乎 has_many 关系正在调用错误的序列化程序。这是错误:

Started GET "/vehicles/1001" for 127.0.0.1 at 2013-04-11 01:07:08 -0700
Processing by UsersController#index as JSON
  Parameters: {"user"=>{}}
  [1m[36mUser Load (0.2ms)[0m  [1mSELECT `users`.* FROM `users` [0m
Processing by VehiclesController#show as JSON
Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.2ms)
  Parameters: {"id"=>"1001", "vehicle"=>{}}
  [1m[35mVehicle Load (0.6ms)[0m  SELECT `vehicles`.* FROM `vehicles` WHERE `vehicles`.`id` = 1001 LIMIT 1


Started GET "/vendor_reps" for 127.0.0.1 at 2013-04-11 01:07:08 -0700
Completed 500 Internal Server Error in 4ms

NoMethodError (undefined method `serializable_hash' for #<ActiveModel::ArraySerializer:0x007fbbcaa82018>):
  app/controllers/vehicles_controller.rb:20:in `block (2 levels) in show'
  app/controllers/vehicles_controller.rb:18:in `show'


Processing by VendorRepsController#index as JSON
  Parameters: {"vendor_rep"=>{}}
  [1m[35mVendorRep Load (0.3ms)[0m  SELECT `vendor_reps`.* FROM `vendor_reps` 
Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.3ms)
  Rendered /Users/pzuraq/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.3ms)
  Rendered /Users/pzuraq/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered /Users/pzuraq/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (11.7ms)

代码在此处列出:https ://gist.github.com/pzuraq/5361607

4

1 回答 1

6

所以事实证明,使用 :option 作为属性名称会导致冲突。可能还有其他相互冲突的名称。必须小心命名空间!

于 2013-04-15T00:19:48.307 回答