require unable to load existing file?

M

Mohammad El-abid

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.
 
R

Rob Biedenharn

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

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:
require_relative 'models/user'

Or:
require File.expand_path('models/user.rb', File.dirname(__FILE__))

-Rob


Rob Biedenharn
(e-mail address removed) http://AgileConsultingLLC.com/
(e-mail address removed) http://GaslightSoftware.com/
 
M

Mohammad El-abid

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

require in 1.9.2 and 1.9.1 5
Ruby 1.9.2 require issue 2
How does ActiveRecord do it? 4
cannot load watir 7
require command problem 4
require v load 4
"Load" Works, But "Require" Doesn't? 4
gem fails to load? 2

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top