ActiveModel::Serializers::Xml get's wrong type when redefining attributes names

niekvdm

New Member
My goal is to make an API to get data from the database, but I'm trying to encapsulate using different names for table fields.So the field Cod_Fornec will be codigo, and Des_RazSoc will be razao_social.And when I call to_xml, I only want the select fields to appear in the return.I'm using ActiveRecord as you will see in the sample code, and that's how a managed to do that.\[code\]class Fornecedor < ActiveRecord::Base set_table_name :FORNE set_primary_key :Cod_Fornec alias_attribute :codigo, :Cod_Fornec alias_attribute :razao_social, :Des_RazSoc def attributes { 'codigo' => '0', 'razao_social' => 'nil' } endend\[/code\]It's almost like I want, except for yje type="NilClass" XML attribute for every field.\[code\]<?xml version="1.0" encoding="UTF-8"?><fornecedor> <codigo type="NilClass">3</codigo> <razao-social type="NilClass">AKZO IND E COMERCIO LTDA</razao-social></fornecedor>\[/code\]Is there a way to not get this type attribute at the XML or solve this problem another way ?That's the output without using attributes or alias_attributes.\[code\]<?xml version="1.0" encoding="UTF-8"?><fornecedor> <Cod-Fornec type="integer">3</Cod-Fornec> <Cod-IBGE type="integer" nil="true"></Cod-IBGE> <Cod-RegTri type="integer">1</Cod-RegTri> <Des-Bairro></Des-Bairro> <Des-Cidade></Des-Cidade> <Des-Endere>R JOAO ALFREDO 353</Des-Endere> <Des-Estado></Des-Estado> <Des-Fantas>ORGANON</Des-Fantas> <Des-Observ nil="true"></Des-Observ> <Des-RazSoc>AKZO IND E COMERCIO LTDA</Des-RazSoc> <Flg-Bloque type="boolean">false</Flg-Bloque> <Flg-NaoRepIcm type="boolean">false</Flg-NaoRepIcm> <Nom-Contat></Nom-Contat> <Num-Cep></Num-Cep> <Num-CgcCpf>06056171900071</Num-CgcCpf> <Num-CgfRg>010.360.090.511</Num-CgfRg> <Num-Fax></Num-Fax> <Num-Fone>011 882-450</Num-Fone> <Per-AcrCus type="decimal">0.0</Per-AcrCus> <Per-Descon type="decimal" nil="true"></Per-Descon> <Per-Markup type="decimal">0.0</Per-Markup> <Qtd-DiaPrz type="integer" nil="true"></Qtd-DiaPrz> <Tip-Descon nil="true"></Tip-Descon></fornecedor>\[/code\]
 
Back
Top