safeguard on absolutify rake task
This commit is contained in:
parent
7f87825186
commit
7477a22421
1 changed files with 16 additions and 14 deletions
|
|
@ -39,22 +39,24 @@ namespace :migrations do
|
||||||
require File.join(Rails.root,"config/environment")
|
require File.join(Rails.root,"config/environment")
|
||||||
|
|
||||||
Photo.all.each do |photo|
|
Photo.all.each do |photo|
|
||||||
# extract root
|
unless photo.remote_photo_path
|
||||||
pod_url = photo.person.url
|
# extract root
|
||||||
pod_url.chop! if pod_url[-1,1] == '/'
|
pod_url = photo.person.url
|
||||||
|
pod_url.chop! if pod_url[-1,1] == '/'
|
||||||
|
|
||||||
if photo.image.url
|
if photo.image.url
|
||||||
remote_path = "#{pod_url}#{photo.image.url}"
|
remote_path = "#{pod_url}#{photo.image.url}"
|
||||||
else
|
else
|
||||||
remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}"
|
remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# get path/filename
|
||||||
|
name_start = remote_path.rindex '/'
|
||||||
|
photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/"
|
||||||
|
photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
|
||||||
|
|
||||||
|
photo.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
# get path/filename
|
|
||||||
name_start = remote_path.rindex '/'
|
|
||||||
photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/"
|
|
||||||
photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
|
|
||||||
|
|
||||||
photo.save!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue