how can i load a file in ruby on rails console?

13,470

Solution 1

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.

Solution 2

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.

Share:
13,470
fenec
Author by

fenec

Updated on June 14, 2022

Comments

  • fenec
    fenec almost 2 years

    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

    • owl
      owl about 14 years
      Please expand your answer to include an example of what you're currently doing in order to load the console.
  • Tom Hundt
    Tom Hundt over 7 years
    I had to put quotes around the filename, to avoid a NameError: undefined local variable or method 'foo'
  • Darpan
    Darpan almost 5 years
    Link is dead perhaps