# Require unable to load existing file?

**URL:** <https://rubytalk.org/t/require-unable-to-load-existing-file/60617>\
**Category:** ruby-talk\
**Created:** [27 October 2010 00:34 UTC](https://rubytalk.org/t/require-unable-to-load-existing-file/60617 "2010-10-27T00:34:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammad\_El-abid](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mohammad\_El-abid](https://rubytalk.org/u/Mohammad_El-abid)\
**Post date:** [27 October 2010 00:34 UTC](https://rubytalk.org/t/require-unable-to-load-existing-file/60617/1 "2010-10-27T00:34:27Z")

</div>

irb(main):001:0\> File.exists? 'models/user.rb'  
=\> true  
irb(main):002:0\> require 'models/user.rb'  
LoadError: no such file to load -- models/user.rb

I'm stumped! As far as I know there is no reason for it to report it as  
"no such file", that if there was a problem with the file it would  
report it.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![John\_Barnette1](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@John\_Barnette1](https://rubytalk.org/u/John_Barnette1)\
**Post date:** [27 October 2010 02:05 UTC](https://rubytalk.org/t/require-unable-to-load-existing-file/60617/2 "2010-10-27T02:05:39Z")

</div>

The current directory isn't in $LOAD\_PATH. Try 'require "./models/user.rb"'.

> **···**
>
> On Oct 26, 2010, at 5:34 PM, Mohammad El-abid wrote:
> 
> > irb(main):001:0\> File.exists? 'models/user.rb'  
> > =\> true  
> > irb(main):002:0\> require 'models/user.rb'  
> > LoadError: no such file to load -- models/user.rb
> > 
> > I'm stumped! As far as I know there is no reason for it to report it as  
> > "no such file", that if there was a problem with the file it would  
> > report it.
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Mohammad\_El-abid](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mohammad\_El-abid](https://rubytalk.org/u/Mohammad_El-abid)\
**Post date:** [27 October 2010 13:04 UTC](https://rubytalk.org/t/require-unable-to-load-existing-file/60617/3 "2010-10-27T13:04:17Z")

</div>

Thank you Rob Biedenharn! Yes I just recently got back into ruby after  
going on PHP for a year or so (which is really way too ugly) and  
switching back to rails. However I do not believe I had used 1.9.x  
before, I was unaware of that change.

Thank you again!  
Mohammad

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Biedenharn1](https://rubytalk.org/u/Rob_Biedenharn1)\
**Post date:** [27 October 2010 12:56 UTC](https://rubytalk.org/t/require-unable-to-load-existing-file/60617/4 "2010-10-27T12:56:28Z")

</div>

You don't specify your Ruby version, but I'm guessing that it is 1.9 since that's where the current directory stopped being on the $LOAD\_PATH by default.

You can either do:  
&nbsp;&nbsp;&nbsp;require\_relative 'models/user'

Or:  
&nbsp;&nbsp;&nbsp;require File.expand\_path('models/user.rb', File.dirname(\_\_FILE\_\_))

-Rob

Rob Biedenharn   
Rob@AgileConsultingLLC.com [http://AgileConsultingLLC.com/](http://AgileConsultingLLC.com/)  
rab@GaslightSoftware.com [http://GaslightSoftware.com/](http://GaslightSoftware.com/)

> **···**
>
> On Oct 26, 2010, at 10:05 PM, John Barnette wrote:
> 
> > On Oct 26, 2010, at 5:34 PM, Mohammad El-abid wrote:
> > 
> > > irb(main):001:0\> File.exists? 'models/user.rb'  
> > > =\> true  
> > > irb(main):002:0\> require 'models/user.rb'  
> > > LoadError: no such file to load -- models/user.rb
> > > 
> > > I'm stumped! As far as I know there is no reason for it to report it as  
> > > "no such file", that if there was a problem with the file it would  
> > > report it.
> > > 
> > > --  
> > > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> > 
> > The current directory isn't in $LOAD\_PATH. Try 'require "./models/user.rb"'.
