Please read for an updated status on RailsCasts:
Learn more or hide this
Ryan, very useful !
Another cool and powerful thing is that you can load (web)session objects straight into your console.
The how-to on this is written on:
You say your models don't always show up in autocompletion. This is just a case of lazy loading, console doesn't know your classes until you've loaded them (you did Project.new in the beginning, which loaded it). Once console's loaded/required your model, it'll auto-complete
Ryan, app.assigns doesn't seem to work with symbols. app.assings['projects'] works!
Great stuff -- I had no idea that 'y' method existed, very handy!
Re assigns -- you can use a symbol if you call the assigns method: app.assigns(:projects)
You can also do inline logging of SQL right in irb:
If you think exiting and re-entering the console sucks, try
Nice tips! :D
A great source of knowledge (and magic tricks!) for my irbrc has been dotfiles.org
There are a bunch of nice .irbrc posted there, as there are some sweet .bashrc and .vimrc files, which might come in handy to some of you :)
I have a link to this screencast in http://thinkingeek.com/index.php?/archives/17-Customizing-IRB.html because I think it's a great one! :)
script/console isn't being "flaky" -- I believe the reason why your "name" method on your project didn't autocomplete until you accessed it because the method is created in the class by ActiveRecord::Base when it notices it doesn't exist (through a call to method_missing) See ActiveRecord::Base define_read_methods.
Often I just want to assign something to a variable, but I don't want to see tons of output, e.g. actors = Actor.find_all.
I discovered that I can eliminate the (large) output by appending a "dummy" command that returns nil or something short like 1.
actors = Actor.find_all ; 1
actors = Actor.find_all ; actors.size
Don't forget Wirble!
It's my favorite console trick.
Just wanted to point out that script/console production --sandbox can be dangerous. Any models objects you load up that way will lock the database for those rows (assuming your db's transactions use a certain form of lock), effectively stopping your site from running. Use with care!
Just an FYI, I had to add
at the top of my .irbrc file before this would work.
here is lot of console trip n trick in rails
FYI: http://errtheblog.com/post/43 link is dead.
How can I load the .irbrc file after the application gets initialized?
First two links had changed their address to:
I have updated the links in the show notes. Thanks for letting us know! :)
First sign in through GitHub to post a comment.