Try changing your code to this:
Dir.foreach(Rails.root.to_s + "/public/dokumente") do |item|
next if item == '.' or item == '..'
file = File.new(Rails.root.to_s + "/public/dokumente/" + item)
img = Photo.new(image: file)
if img.save
file.chmod(0777)
File.delete(Rails.root.to_s + "/public/dokumente/" + item)
end
end