Domanda

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.

È stato utile?

Soluzione

You can get hostname from controller.

request.host
request.host_with_port

Altri suggerimenti

Did you try using RAILS_ROOT?

FileTest.exists?("#{RAILS_ROOT}/public/#{filename}")
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top