Stupid Rails / IRB Console Tricks

27Nov06

I’ve found (and stolen from others) a number of tricks over time to make life in IRB and the Rails console (which is just IRB…) a bit easier. Here are a few to start.

Saving an object to YAML

Periodically, I need to save an object in YAML form. This does the trick –

`echo "#{User.find(1).to_yaml}" > user.yml`

Explanation: The only real trick here is using the fact that enclosing the statement in backticks (`) tells IRB to treat this as a shell command.

Advertisements


No Responses Yet to “Stupid Rails / IRB Console Tricks”

  1. Leave a Comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: