0

ファイルのリストがあり、相対パスを取得しようとしています

file = "/Users/yves/github/local/workshop/public/uploads/craftwork/image/1/a1d0.jpg"
Rails.public_path => "/Users/yves/github/local/workshop/public"

#取得しようとしています=> "uploads / Craftwork / image / 1 / a1d0.jpg"

file.relative_path_from(Rails.public_path) # is wrong 
# raising :  undefined method `relative_path_from' for #<String  ( file is a String..)

# so I tried to use Pathname class
Pathname.new(file).relative_path_from(Rails.public_path)

# but the I get another error
# undefined method `cleanpath' for String

Rails 3.2ではrelative_path_fromは非推奨ですか?はいの場合、今の良いものは何ですか?

4

3 に答える 3

0

これは私が使用したものです:

"#{Rails.root}/public/spreadsheets/file_name.xlsx"
于 2016-09-16T12:32:08.137 に答える