简体   繁体   English

将has_many添加到ActiveModel :: Serializer时出现问题

[英]Issue adding has_many to ActiveModel::Serializer

I've been trying to add has_many relationships to my ActiveModel::Serializers for a while now and I'm getting a bevy of errors related to them. 我已经尝试将has_many关系添加到我的ActiveModel :: Serializers已有一段时间了,并且我收到了很多与它们相关的错误。 It seems like the has_many relationships are calling the wrong serializer. 似乎has_many关系正在调用错误的序列化程序。 Here is the error: 这是错误:

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)

The code is gisted here: https://gist.github.com/pzuraq/5361607 代码位于此处: https ://gist.github.com/pzuraq/5361607

So it turns out that using :option as a property name was causing conflicts. 因此事实证明,使用:option作为属性名称会引起冲突。 There are probably other conflicting names as well. 可能还有其他冲突的名称。 Gotta be careful about the namespace! 要注意名称空间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActiveModel :: Serializer has_many对象的哈希值 - ActiveModel::Serializer has_many hash of objects 如何通过与ActiveModel :: Serializer关联显示has_many: - How can show has_many :through Association with ActiveModel::Serializer 将ActiveModel :: Serializer从v0.9.2迁移到0.8,has_many没有被序列化 - Migrating ActiveModel::Serializer down from v0.9.2 to 0.8, has_many not being serialised ActiveModel :: Serializer:与联接表一起使用的推荐方式(has_many至) - ActiveModel::Serializer: Recommended way to use with join table (has_many through) 具有has_and_belongs_to_many的ActiveModel Serializer - ActiveModel Serializer with has_and_belongs_to_many 如何将 ActiveModel::Serializer:has_many 关联的密钥格式(即驼峰式)指定为一次性选项(不是全局配置)? - How to specify the key format (i.e. camelcase) for an ActiveModel::Serializer :has_many association as a one-off option (not global config)? 用于 has_many 查询的 Jsonapi 序列化程序参数 - Jsonapi serializer parameters to has_many query Rails 4:在序列化器中订购has_many - Rails 4: Order has_many in serializer Rails ActiveModel 使用单个 class 设计 belongs_to 和 has_many - Rails ActiveModel designing belongs_to and has_many with single class ActiveModel Serializers:has_many 在运行时有条件? - ActiveModel Serializers: has_many with condition at run-time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM