Don't show XML attributes if they ar eblank or nil

Hi, I’m creating a dynamic xml file using builder in Rails, which pulls
from several different related tables. Some of my nodes include
attributes, but some don’t. I would like to find a way to leave out
those attributes that are blank.

My XML now:

Vermont
27%

Hawaii 100%

should look like this:

Vermont
27%

Hawaii 100%

without the blank type="" attribute.

My .builder includes this:

@table.each do |r|
xml.row(:line => r[0], :type=> r[1]) do
r.each do |i|
xml.cell(i, :column_id => ‘’)
end
end
end

I can make the value for :type => nil, but I still get the blank
attribute. I tried conditionals inside the node, but that didn’t work.
Any ideas?

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs