views:

306

answers:

3

I'm always making the same steps when I do:

script/console

do you know some file to edit or something similiar to avoid doing always the same, like for example loading some particular required gem (in my casi 'spawners' :))

A: 

With irb, ~/.irbrc serves for that purpose. Not sure whether Rails console uses it though.

Mladen Jablanović
+4  A: 

Create a file called .irbrc in your home directory and any Ruby code you put in there will be executed at the beginning of your console session. There's lots of cool improvements you can make to the console experience this way, e.g. these from Dr. Nic (the end of that article also has instructions for getting .irbrc working in Windows).

Jordan
really cool, thanks a lot, I thinkg that my question was pretty basic :) thanks!
ClaudioA
Mm.. I'm having a problem... I have this in my irbrcrequire 'rubygems'require 'irb/completion'require 'map_by_method'require 'what_methods'require 'pp'require 'spawners'IRB.conf[:AUTO_INDENT]=truebut spawners is not working :( any idea?
ClaudioA
Sorry, I'm not familiar with spawners. Does it work if you just type in "require 'spawners'" after your session begins?
Jordan
Yes, that is exactly what I want to stop doing :) When I do script/console, then I do _require 'spawners'_ all the time.. and adding require 'spawners' to irbrc is not working because my env is not loaded at the time that the irbrc is executed :(
ClaudioA
Sorry, I haven't got a solution. I'd recommend debugging your .irbrc like you'd debug any other Ruby code, to see if you can figure out if it's getting tripped up somewhere (start with removing everything except the spawners line).
Jordan
A: 

The question still stands, this is not a complete solution for initializing rails console,

what if I want to do something related to active record specific like

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.clear_active_connections!

it throws back error uninitialized constant ActiveRecord

is there something that can be loaded only when the "rails console" is initialized and does not have any side effects on application code.

Thanks, Amir

Amiruddin Nagri