我想要的绝对路径是/Users/Hsu-Wei-Cheng/Dropbox/Rails/zeus/public/uploads/local_display_multi_lang/xml/8/results.zip
/uploads/local_display_multi_lang/xml/8/results.zip
存储在local_display_multi_lang.result
所以我尝试使用Rails.root.join
方法获取系统中的绝对路径。
按Rails.root.join("public", local_display_multi_lang.result.to_s)
但它没有用,我得到了:/uploads/local_display_multi_lang/xml/8/results.zip
我犯了什么错误?感谢
[3] pry(#<#<Class:0x007fe7ae84f038>>)> Rails.root.join("public", local_display_multi_lang.result.to_s)
=> #<Pathname:/uploads/local_display_multi_lang/xml/8/results.zip>
[4] pry(#<#<Class:0x007fe7ae84f038>>)> Rails.root
=> #<Pathname:/Users/Hsu-Wei-Cheng/Dropbox/Rails/zeus>
[5] pry(#<#<Class:0x007fe7ae84f038>>)> local_display_multi_lang.result.to_s
=> "/uploads/local_display_multi_lang/xml/8/results.zip"
[6] pry(#<#<Class:0x007fe7ae84f038>>)> Rails.root.join("public")
=> #<Pathname:/Users/Hsu-Wei-Cheng/Dropbox/Rails/zeus/public>
[7] pry(#<#<Class:0x007fe7ae84f038>>)> local_display_multi_lang.result.to_s
=> "/uploads/local_display_multi_lang/xml/8/results.zip"
[8] pry(#<#<Class:0x007fe7ae84f038>>)> Rails.root.join("public", local_display_multi_lang.result.to_s)
=> #<Pathname:/uploads/local_display_multi_lang/xml/8/results.zip>
[9] pry(#<#<Class:0x007fe7ae84f038>>)> Rails.root.join("public", local_display_multi_lang.result)
=> #<Pathname:/uploads/local_display_multi_lang/xml/8/results.zip>
答案 0 :(得分:1)
因为local_display_multi_lang.result.to_s
是绝对路径。
尝试
Rails.root.join("public", local_display_multi_lang.result.to_s[1..-1])