Reputation: 6037
I need to run a few commands whenever I start my Rails console, like setting up the logger, or to set the time to my time zone.
Right now I'm copying and pasting these commands after Rails is started. Can I write a script to make these commands run automatically after IRB is started?
Upvotes: 3
Views: 1374
Reputation: 4272
I wrote an extended answer to this in another question but the short answer is that if you are using Rails 3 or above you can use the console method on YourApp::Application to make it happen:
module YourApp
class Application < Rails::Application
...
console do
Time.zone = A.info.time_zone
end
end
end
Upvotes: 1
Reputation: 160551
Rails' console is IRB. IRB supports an .irbrc file, which contains initialization information and settings.
Read "https://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick" and "My .irbrc for console/irb" for ideas.
Upvotes: 7