Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 将中第一级关联的命名模式更改为_xml(ActiveRecord::Serialization)_Ruby_Rails Activerecord - Fatal编程技术网

Ruby 将中第一级关联的命名模式更改为_xml(ActiveRecord::Serialization)

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

ActiveRecord的序列化允许您包括第一级关联(使用: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}}
正确的语法是

  firm.to_xml :dasherize => false, include: {:account => {:dasherize => false}}

如果您使用的是Ruby 1.9.x或更高版本:

firm.to_xml dasherize: false, include: { account: { dasherize: false } }