You might want to move this functionality to a method similar to what I did with remote_path_to(file) method.