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