ruby - rails 3: hash attribute in a override to_xml model method -


i wrote override to_xml model method , right im trying hash attribute transformed set if symbol => values pair had no success.

the result of intersected_categories method hash like:

{:"1"=>["broken board", false], :"2"=>["sticking", false], :"3"=>["bottom tier missing", false], :"4"=>["bad i/l", false], :"5"=>["delamination", false], :"7"=>["sheet level - smile", false], :"8"=>["sheet level - frown", false], :"9"=>["missing ss", false]} 

the to_xml method

def to_xml (options={})   xml = options[:builder] ||= builder::xmlmarkup.new(:indent => options[:indent])   xml.instruct! unless options[:skip_instruct]   xml.wip @wip,   :number => self.number,   :start_time => self.wip_start_time,   :end_time => self.wip_end_time,   :line => self.system.name,   :shift => self.shift,   :crew => self.crewf,   :sm_crew => self.crewsm,   :sm_shift => self.shiftsm,   :product => self.smmaingroup,    :product_group => self.product_group,    :sheets => self.sheets,   :interleavers => self.interleavers,   :wip_grade => self.intersected_categories,   :comment => self.comment end 

ive tried couple of things no success:

def to_xml (options={})   xml = options[:builder] ||= builder::xmlmarkup.new(:indent => options[:indent])   xml.instruct! unless options[:skip_instruct]   @wip.intersected_categories.each |grade|     wip_categories << {grade[1][0].to_sym => grade[0][1]}   end   .   .   :comment => self.comment,   wip_categories #explodes end  ###### try   :interleavers => self.interleavers,   :wip_grade => self.intersected_categories,   :comment => self.comment,   self.intersected_categories.each |grade|     << grade[1][0].to_sym => grade[0][1] #with / without {} keeps failing   end end 

any idea how can achieve need?

update

current xml:

 <wip number="123h11008" start_time="2014-05-13 09:21:00 -0500" end_time="" line="cl1" shift="1" crew="a" sm_crew="a" sm_shift="1" product="1111111" product_group="g2" sheets="0" interleavers="0" wip_grade="{:"2"=>["bottom tier missing", false], :"3"=>["falling", false], :"4"=>["broken boards", false], :"5"=>["crown", false], :"6"=>["dip", false], :"7"=>["green boards", false], :"8"=>["delamination", false], :"9"=>["bad i/l", false]}" comment=""/> 

expected xml:

 <wip number="123h11008" start_time="2014-05-13 09:21:00 -0500" end_time="" line="cl1" shift="1" crew="a" sm_crew="a" sm_shift="1" product="1111111" product_group="g2" sheets="0" interleavers="0" bottom tier missing=false falling =  false broken boards = false crown = false dip = false green boards = false delamination = false bad i/l = false comment=""/> 

try:

xml.wip @wip, {  :number => self.number,  :start_time => self.wip_start_time,  :end_time => self.wip_end_time,  :line => self.system.name,  :shift => self.shift,  :crew => self.crewf,  :sm_crew => self.crewsm,  :sm_shift => self.shiftsm,  :product => self.smmaingroup,   :product_group => self.product_group,   :sheets => self.sheets,  :interleavers => self.interleavers,  :comment => self.comment }.merge(hash(self.intersected_categories.values)) 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -