FileTest.exists? let out ruby ​​on rails

I am trying to check if a file exists in my rails application. I am running ruby ​​1.8.6 and rails 2.1.2 with Windows XP.

So the problem is that FileTest.exists? the method does not seem to work. I simplified the code to this point:

if FileTest.exists?("/images/header.jpg")
      render :text => "yes"
else  
      render :text => "no <img src='/images/header.jpg' />"
end

If I do this, the system will display “no,” and then display an image that displays correctly because /images/header.jpg exists.

I tried FileTest.exists ?, FileTest.exist ?, File.exists ?, File.exist? and nothing works.

What am I doing wrong? Thanks

+3
source share
2 answers

, , "header.jpg" "images" ( Windows , "c: \" ). ( ) "/images", URL-.

, @Brian, :

FileTest.exists?(RAILS_ROOT + "/images/header.jpg") #  < rails 3.0
FileTest.exists?(Rails.root + "/images/header.jpg") # >= rails 3.0
+14

RAILS_ROOT , , ?

+3

Source: https://habr.com/ru/post/1706829/


All Articles