我正在使用Carrierwave上传文件。我试图从Rails中的文件中读取,我尝试打开它的任何方法都会返回错误。
如果我使用,则返回false
:
File.exists(file_url)
如果我尝试使用:
File.open(file_url, 'r'),
我收到错误:
Errno::ENOENT: No such file or directory - /uploads/document/file/2/doc-sample-file.txt
from (irb):5:in `initialize'
from (irb):5:in `open'
from (irb):5
from /Users/xxx/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/xxx/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/xxx/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
如果我尝试在视图中加载已上传到Carrierwave的文件,如图像,则没有问题。我也可以在浏览器中访问文件路径,但是方法找不到路径。