Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run command on Rails Console startup

Is there a way to run a specific command when the rails console starts? I'd like it to print out whether or not I'm connected to the remote or local database in BIG LETTERS! I don't mind writing a custom method to determine that– I'm just asking how to write to the console. I've seen errors and alerts there before.

For example: rails c prints out Loading development environment (Rails 3.2.11) **USING REMOTE DATABASE** 1.9.3p125 :001 >

like image 798
Brian Weinreich Avatar asked Jun 18 '13 14:06

Brian Weinreich


1 Answers

You can write ruby code in irb config file. Edit the .irbrc file and add your ruby code used to determine whether you connected to local or remote

if defined? Rails
   //ruby code to find you connected to local or remote
   puts "USING REMOTE DATABASE...."
end
like image 123
RameshVel Avatar answered Oct 16 '22 16:10

RameshVel