xxjjnn
xxjjnn

Reputation: 15239

rails console list directory

I am trying to load a script into Rails console. In order to load the file, I need to do something like:

load scripts/my_script.rb
# This doesn't work... gives this error:
NameError: undefined local variable or method `scripts' for main:Object

load ./scripts/my_script.rb
ArgumentError: wrong number of arguments (0 for 1)

load "./scripts/my_script.rb"
LoadError: cannot load such file -- ./scripts/my_script.rb
# I feel like supermode. Tell me whyyy?

I suspect that I start off in my base rails directory, so if Rails console's "ls" command did as the terminal did (it doesn't), it would list:

app/
config/
scripts/
Gemfile
etc

What commands can I use from within Rails console to navigate around, list the contents of the current directory, and reveal what directory Rails console is currently in?

Or if this is not possible, please spare my sanity and explain why the load command with the directory and filename (and permutations) are not working.

Extra note: I need to reload different files as I make changes to them - so starting the console passing a single filename is no good.

Upvotes: 2

Views: 2629

Answers (1)

Rahul garg
Rahul garg

Reputation: 9362

Do you want to do some operations on some ruby files from console?

You can use

Dir.pwd

to get current Directory, and can use other File related methods to require a file.

Upvotes: 4

Related Questions