very cool!~
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:
http://tektastic.wordpress.com/2006/12/06/ruby-on-rails-how-to-load-session-objects-into-console/
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:
http://toolmantim.com/article/2007/2/6/system_wide_script_console_logging
If you think exiting and re-entering the console sucks, try
>> reload!
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.
E.g.
actors = Actor.find_all ; 1
or
actors = Actor.find_all ; actors.size
Mike
Mike
Don't forget Wirble!
It's my favorite console trick.
Hey,
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
require 'rubygems'
at the top of my .irbrc file before this would work.




