expand_path
![Extensive documentation Importance_4](https://d2vfyqvduarcvs.cloudfront.net/images/importance_4.png?1349367920)
expand_path(*args)
public
Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. The given pathname may start with a “~”, which expands to the process owner’s home directory (the environment variable HOME must be set correctly). “~user” expands to the named user’s home directory.
File.expand_path("~oracle/bin") #=> "/home/oracle/bin"
A simple example of using dir_string is as follows.
File.expand_path("ruby", "/usr/bin") #=> "/usr/bin/ruby"
A more complex example which also resolves parent directory is as follows. Suppose we are in bin/mygem and want the absolute path of lib/mygem.rb.
File.expand_path("../../lib/mygem.rb", __FILE__) #=> ".../path/to/project/lib/mygem.rb"
So first it resolves the parent of __FILE__, that is bin/, then go to the parent, the root of the project and appends lib/mygem.rb.
![Default_avatar_30](https://www.gravatar.com/avatar/b850a6cd0c0f8993fa152645ca9a7fbd?size=30&default=http://apidock.com/images/default_avatar_30.png)
Argument Ordering
Be aware that the order of arguments for this method is the opposite of File.join:
File.expand_path('foo', '/bar') # => "/bar/foo" File.join('foo', '/bar') # => "foo/bar"
![Default_avatar_30](https://www.gravatar.com/avatar/54e74983d81fa2fbe4c28e8392532f18?size=30&default=http://apidock.com/images/default_avatar_30.png)
Require file from the same folder
If you want to require file from the same folder, the simplest way is
require File.expand_path('../file-to-require', __FILE__)
If your file is /lib/book.rb
File.expand_path('../page', '/lib/book.rb') => '/lib/page.rb'
![Default_avatar_30](https://www.gravatar.com/avatar/9afdfc6fdec827bc2515a08e38f8e83e?size=30&default=http://apidock.com/images/default_avatar_30.png)
Anothery way
This Worked For Me
require File.expand_path('../app/models/extenstions/active_record_ext', File.dirname(__FILE__))
I did this in application.rb