我正在使用以下方法保存抓取的图像:
img_url = agent.page.at(".field-content a")[:href]
root_img_url = URI.join(page_url,img_url).to_s
cover = File.basename(root_img_url)
file = File.open(File.join(Rails.root, 'app', 'assets', 'images', cover), 'wb') { |f|
f.write(open(root_img_url).read)
}
一些图像%26
的名称中有一个,比如cover_b%26w_xyz_.jpg
,当我将它们保存在我的数据库中并希望在我的索引视图中查看它们时,它们不会出现,但仍保存在 assets/images 文件夹中。
在将文件保存到数据库之前如何替换%26
字符cover
?