Find and replace entire HTML nodes with Nokogiri
i have an HTML, that should be transformed, having some tags replaced with another tags. I don't know about these tags, because they will come from db. So, set_attribute or name methods of Nokogiri are not suitable for me. I need to do it, in a way, like in this pseudo-code: def preprocess_content doc = Nokogiri::HTML( self.content ) doc.css("div.to-replace").each do |div| # "get_html_text" will obtain HTML from db. It can be anything, even another tags, tag groups etc. div.replace self.get_html_text end self.content = doc.css("body").first.inner_html end I found Nokogiri::XML::Node::replace