Question

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.

Was it helpful?

Solution

You can get hostname from controller.

request.host
request.host_with_port

OTHER TIPS

Did you try using RAILS_ROOT?

FileTest.exists?("#{RAILS_ROOT}/public/#{filename}")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top