문제

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