如何使用nokogiri替换所有带图像标签的img标签?这是为了利用Rails自动插入正确资产服务器的能力?使用Nokogiri用<%= image_tag%>替换<img src />标签?
require 'nokogiri'
class ToImageTag
def self.convert
Dir.glob("app/views/**/*").each do |filename|
doc = Nokogiri::HTML(File.open(filename))
doc.xpath("//img").each |img_tags|
# grab the src and all the attributes and move them to ERB
end
# rewrite the file
end
rescue => err
puts "Exception: #{err}"
end
end
也许你可以用一个例子来澄清你想要做什么,为什么? 是您想要更改资产服务器,并添加缓存清除时间戳吗? – 2011-06-15 19:28:21