I seem to be having trouble with Rails finding the appropriate path to a textfile I would like to load into memory for processing, for a personal learning project.
require '#{RAILS_ROOT}/lib/english.txt'
or
require '/lib/english.txt'
are not working.
The textfile is located in the lib directory.
I am trying to load it from a simple controller. I continue to get errors:
MissingSourceFile in EntriesController#anagram no such file to load -- /Users/me/Sites/cvtest/lib/english.txt
The above path is actually where the file is located according to my computer’s info (OSX). What is it that I am doing incorrectly? Thank you.
If the file contains Ruby code, change the extension to rb. Chances are rails will just load the file automatically without any require being necessary. At worst
require 'english'orrequire 'lib/english'should be all you need.require is for loading Ruby code extensions, libraries and what-have-you.
If english.txt doesn’t contain valid Ruby code, then require isn’t what you’re looking for, there’s nothing to see here, move along. Investigate the many wonders of the File class.