How to run some code only when the rails console starts, kind of like an rc file?

前端 未结 1 579
无人及你
无人及你 2021-01-11 18:13

Is there a way to execute some code that is run only when the console starts? Kind of like an rc file (.bashrc, .zshrc, etc.)? I find myself always

相关标签:
1条回答
  • 2021-01-11 18:47

    If you use irb, just add a method in ~/.irbrc (create one if does not exist):

    def find_by_username(username)
      User.find_by_username('my_console_user')
    end
    

    Or add to ~/.pryrc if you use pry-rails.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题