Is there a reason you are reusing an instance variable @doc?
When it comes to resolving such issues, I find it best to try to evaluate the same code without the overhead of Rails. For instance:
require 'nokogiri'
doc = Nokogiri::HTML(DATA)
doc.css("p").each do |p|
p.remove if p["class"] == "why"
end
__END__
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Test data</p>
<p>More <a href="http://stackoverflow.com">Test Data</a></p>
<p class="why">Why is this still here?</p>
</body>
</html>
What returns:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>Test</title></head>
<body>
<p>Test data</p>
<p>More <a href="http://stackoverflow.com">Test Data</a></p>
</body>
</html>
paragraphs = @doc.css("p"), paragraphs.each .. , .