I need the Ruby module FileUtils
to handle some operations with files.
I want to test that this require will work correctly in my controller. So I tried this in my console but got false
as a result (this works fine when I'm not in a Rails console but just a plain Ruby console):
- Go to the root directory of my project
$ rails c
to open my console> require 'fileutils'
returnsfalse
.
What is the correct way to require a module via rails console? Why would this return false?
I'm assuming in my controller I can just do something like this, correct?
def create
require 'fileutils'
# my code that uses fileutils.
end
A
false
response fromrequire
means that the module is already loaded. You should be good to go without requiring this in your controller. See docs: http://www.ruby-doc.org/core-2.1.1/Kernel.html#method-i-requireIt is most likely already required by default. Just type
FileUtils
in the console, it should respondReturning
false
fromrequire
means that it's already loaded.Try this from the console: