Ruby on rails Errno::enoint:没有这样的文件或目录
如何修复错误Ruby on rails Errno::enoint:没有这样的文件或目录,ruby-on-rails,ruby,amazon-web-services,amazon-s3,aws-sdk,Ruby On Rails,Ruby,Amazon Web Services,Amazon S3,Aws Sdk,如何修复错误Errno::enoint:没有这样的文件或目录-/app/tmp/sitemaps?我有一个文件:tmp/sitemaps/sitemap.xml.gz $ heroku run rake sitemap:upload_to_s3 Running rake sitemap:upload_to_s3 on livetochallenge.... up, run.2043 Starting sitemap upload to S3... rake aborted! Errno::ENO
Errno::enoint:没有这样的文件或目录-/app/tmp/sitemaps
?我有一个文件:tmp/sitemaps/sitemap.xml.gz
$ heroku run rake sitemap:upload_to_s3
Running rake sitemap:upload_to_s3 on livetochallenge.... up, run.2043
Starting sitemap upload to S3...
rake aborted!
Errno::ENOENT: No such file or directory - /app/tmp/sitemaps
这是lib/tasks/sitemap.rake:
# Code Based Upon Comment Made In Below Tutorial Unless Specified Here
namespace :sitemap do
desc 'Upload the sitemap files to S3'
task upload_to_s3: :environment do
puts 'Starting sitemap upload to S3...'
s3 = Aws::S3::Resource.new
bucket = s3.bucket(ENV['AWS_BUCKET']) # I refer to it as AWS not S3. I couldn't figure out the latter and not sure if it makes a difference. In production.rb paperclip_defaults I set it :bucket => ENV['AWS_BUCKET']
Dir.entries(File.join(Rails.root, 'tmp', 'sitemaps')).each do |file_name|
next if %w(. .. .DS_Store).include? file_name
path = "sitemaps/#{file_name}"
file = File.join(Rails.root, 'tmp', 'sitemaps', file_name)
object = bucket.object(path)
object.upload_file(file)
puts "Saved #{file_name} to S3"
end
end
config/sitemap.rb:
SitemapGenerator::Sitemap.default_host = 'http://www.livetochallenge.com/'
SitemapGenerator::Sitemap.public_path = 'tmp/sitemaps/'
SitemapGenerator::Sitemap.create do
add challenges_path, changefreq: 'daily'
Challenge.find_each do |f|
add challenge_path(f), lastmod: f.updated_at
end
end
SitemapGenerator::Sitemap.ping_search_engines
routes.rb
get '/sitemap.xml.gz', to: redirect("https://#{ENV['AWS_BUCKET']}.s3.amazonaws.com/sitemaps/sitemap.xml.gz"), as: :sitemap
我正在使用AWS SDK v2.2.31
我遵循了教程。文件是源代码管理的一部分吗?与S3无关
File.join(Rails.root,'tmp','sitemaps')
似乎表明Rails.root
的评估结果为“/app”--因此您可能应该修复它,其余的都会正确。刚刚测试了@Michael sqlbot。错误依然存在。也许是我干的。我把File.join('/app',tmp',sitemaps')
放到了我想要的位置。你的应用程序显然不在/app
——它在其他地方,因此你需要正确的目录,而不是/app
——这就是你出错的原因。啊,你是对的。这是一个活生生的挑战。我拍了一张照片,因为我仍然得到错误Errno::enoint:没有这样的文件或目录-LiveToChallenge/tmp/sitemaps
。你介意提供一个答案,告诉我该如何写@Michael sqlbot吗?