Ruby 将中第一级关联的命名模式更改为_xml(ActiveRecord::Serialization)
ActiveRecord的序列化允许您包括第一级关联(使用:include),以及更改命名约定(通过:dasherize或:camelize)。将两者放在一起看起来是这样的:Ruby 将中第一级关联的命名模式更改为_xml(ActiveRecord::Serialization),ruby,rails-activerecord,Ruby,Rails Activerecord,ActiveRecord的序列化允许您包括第一级关联(使用:include),以及更改命名约定(通过:dasherize或:camelize)。将两者放在一起看起来是这样的: firm.to_xml :dasherize => false, include: :account 这只会更改公司字段的命名约定,而不会更改帐户的命名约定。我尝试了以下方法,这些方法会返回语法错误: firm.to_xml :dasherize => false, include: :account
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}}
正确的语法是
firm.to_xml :dasherize => false, include: {:account => {:dasherize => false}}
如果您使用的是Ruby 1.9.x或更高版本:
firm.to_xml dasherize: false, include: { account: { dasherize: false } }