10

Is there a way to get "rails console" to load .irbrc? Or am I supposed to use something else?

2
  • 8
    If your rails console comes up with a prompt that says pry(main), use .pryrc instead. Feb 13, 2017 at 14:48
  • I found this question when trying to diagnose my own issue. Turns out I did not have .irbrc in ~/. Once I put it there (or rather simlinked) it worked exactly as expected. Double check just so you do not look foolish like I did :-P
    – Aaron
    Mar 22, 2017 at 16:18

2 Answers 2

15

rails console by default loads ~/.irbrc, so I don't really understand your question. It will, however, fail silently (and do not load it) if there are some errors in this file.

One example of such error is requiring gems not defined in the Gemfile (for Rails3 + Bundler) and not rescuing from LoadErrors (or expecting the require to "just work").

1
  • 4
    I was just playing around with this and it turns out that if I add a .irbrc file to the root of a project, it won't work unless I also have a ~/.irbrc file. Jul 25, 2012 at 1:03
1

rails c does not load any other .irbrc but from the current user's home (~).

See https://gist.github.com/railsbros-dirk/719848

You can tweak your rails application.rb to load the root .irbrc file if present.

1
  • 4
    how can we change application.rb to load .irbrc for project's root folder? Jun 11, 2020 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.