0

I am simply trying to get the root path to look up a file on my machine, I am pretty new to RoR. Is there some sort of variable somewhere so I could do something like this:

def path
    return '{#ROOT}/some/path/file.txt'
end

I do not want the Rails root, I want the machine root.

naspinski
  • 34,020
  • 36
  • 111
  • 167

2 Answers2

3

Just replace your method with:

def path
  "/some/path/file.txt"
end

Since root is always /, and return isn't necessary in Ruby.

Jason Whitehorn
  • 13,585
  • 9
  • 54
  • 68
0

If you are trying to get the file path, and not the URL path, this will provide the absolute file path of your rails root folder:

Rails.root

From there, you could simple add on the rails path to your file, as your rails directory structure should be static:

def path
    return "{#Rails.root}/some/path/file.txt"
end
lightswitch05
  • 9,058
  • 7
  • 52
  • 75