ActiveRecord的to_xml序列化允许您包含第一级关联(使用:include),以及更改命名约定(通过:dasherize或:camelize)。将两者放在一起看起来像这样:
firm.to_xml :dasherize => false, include: :account
这只会更改公司字段的命名约定,而不会改变帐户的命名约定。我尝试过以下操作,这会抛出语法错误:
firm.to_xml :dasherize => false, include: :account {:dasherize => false}
firm.to_xml :dasherize => false, include: {:account {:dasherize => false}}
答案 0 :(得分:1)
如果您使用的是Ruby 1.9.x或更高版本:
firm.to_xml dasherize: false, include: { account: { dasherize: false } }
答案 1 :(得分:0)
正确的语法是
firm.to_xml :dasherize => false, include: {:account => {:dasherize => false}}