If you’re processing HTML with Hpricot and want to change the attributes on a tag in a search block, beware that the attributes method on an element returns a copy of the actual attributes. In order to change the real attribute on the element, you need to set raw_attributes on it. Here’s what I had to do, boiled down to the scum on the pan:
doc = Hpricot(html)
doc.search("img").each do |element|
# do some processing here, calculating the new attribute value
# ...
element.raw_attributes = element.attributes.merge("src" => new_src)
end
# now save the tweaked document
file.write(doc.to_html)
BarCamp was a blast yesterday. I met some really great and smart people, and my presentation went over very well. I think we’ll have some more people using Radiant in the near future. For those who didn’t get to see my presentation, or want to review what they did see, click below for a 