method

root

rails latest stable - Class: Rails
root()
public

Returns a Pathname object of the current Rails project, otherwise it returns nil if there is no project:

Rails.root
  # => #<Pathname:/Users/someuser/some/path/project>

2Notes

example

ronald · Jun 4, 20092 thanks

==== Ruby style Dir[File.join(RAILS_ROOT, 'vendor', 'plugins', '')] ==== Rails style Dir[Rails.root.join('vendor', 'plugins', '')]

Possible gotcha

szeryf · Feb 25, 20102 thanks

This method returns a Pathname object which handles paths starting with a / as absolute (starting from the root of the filesystem). Compare:

>> Rails.root
=> #<Pathname:/some/path/to/project>
>> Rails.root + "file"
=> #<Pathname:/some/path/to/project/file>
>> Rails.root + "/file"
=> #<Pathname:/file>
>> Rails.root.join "file"
=> #<Pathname:/some/path/to/project/file>
>> Rails.root.join "/file"
=> #<Pathname:/file>