I really like to write this line every time I want to open the Rails console:
irb(main):001:0> ActsAsTenant.current_tenant = User.find(1).account
Is there a way to run the / script command before each call to "rails c" / "irb"?
Thanks in advance!
Put the code you want to execute in the file .irbrcin the root folder of your project:
.irbrc
echo 'ActsAsTenant.current_tenant = User.find(1).account' >> .irbrc bundle exec rails c # ⇐ the code in .irbrc got executed
Sidenote: Use Pryinstead of stupidity IRB. Try it and you will never give up.
Pry
IRB
You can put your installation code in an rb file, for example:
foo.rb:
def irb_setup ActsAsTenant.current_tenant = User.find(1).account end
run irb as follows:
irb -r ./foo.rb
( )
2.3.0 :001 > init_irb
, , , - , , . , .