am trying to load a file where i have all my setting into rails console. i want to do it because when i use the console there is too much repetition . thank you
Reload: This command will allow you to make changes to your code, and continue to use the same console session without having to restart. Simply type in the “reload!” command after making changes and the console will reload the session.
The simplest way is with rails runner because you don't need to modify your script. runner runs Ruby code in the context of Rails non-interactively. If you make the script executable by running chmod +x script. rb , you can add #!/usr/bin/env rails runner to the top of the script, and then simply run it with ./script.
Interactive Ruby If you're using macOS open up Terminal and type irb , then hit enter. If you're using Linux, open up a shell and type irb and hit enter. If you're using Windows, open Interactive Ruby from the Ruby section of your Start Menu.
You can set configs of IRB using .irbrc
file located in your home directory.
You can use load
, require
and whatever you want there.
Adding something like require 'rubygems'
and require 'pp'
will help. Some people customize the file more heavily. See this for example.
From within Rails console or IRB you can load a file with the require method. For example require foo.rb
will execute all the statements in foo.rb
. You can use relative or absolute paths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With