質問

In a Rails model how can I check if a URL on the same Rails server exists?

I'm using dragonfly and am trying to check the existence of an image from a path such as /media/BAhbBlsHOgZmIikyMDExLzExLzIxLzEwXzNxXzQyXzI5NF9Wb3NraG9kMi5qcGc

FileTest.exists? won't work because I don't have the file path and I can't open the URL because I don't have the server hostname.

役に立ちましたか?

解決

You can get hostname from controller.

request.host
request.host_with_port

他のヒント

Did you try using RAILS_ROOT?

FileTest.exists?("#{RAILS_ROOT}/public/#{filename}")
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top