我正在使用 open-uri 和 seed.db 文件。我正在尝试使用“rake db:seed --trace”运行以下代码:
CSV.foreach("vendor/users1.csv", { :col_sep => ",", :quote_char => "\"", :headers => true}) do |row|
user = User.find_by_email("sample#{i}@foobardne.com")
if (!user.picture_url.nil?)
begin
file = open user.picture_url
user.avatar = file
rescue OpenURI::HTTPError => error
user.avatar = nil
rescue OpenURI::HTTPRedirect => redirect
user.avatar = nil
end
user.password = user.password_confirmation = "foobar"
user.save
end
出于某种原因,每次我运行命令时,它都无法识别我的第二个重定向救援语句,并且我得到以下输出(我缩短了结尾):
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
rake aborted!
redirection forbidden: http://cellbio.med.harvard.edu/faculty/artavanis/images/artavanis4_2002.jpg -> https://cellbio.med.harvard.edu/faculty/artavanis/images/artavanis4_2002.jpg
知道为什么我的代码没有捕捉到重定向错误吗?任何帮助都非常感谢!