the many methods to #find things in Rails · Nov 22, 2006
For the longest time, I didn’t understand the full power of the various #find methods in Rails. I probably still don’t, but my understanding of them has certainly expanded. I used to use plain #find for everything. If I wanted to find all rows in the table ‘groups’ that had an ‘id’ field value of 1, 2, 3, or 4, I would do something like this:
#post method in tests with a different controller · Nov 14, 2006
I wanted a #login method in test_helper that would allow me to easily login from any of my functional tests. However, the #post method won’t allow you to set a different controller than the one in the @controller instance variable that’s defined in your test’s #setup. Well, by looking at how the #process method works, you can see that it just grabs the controller from @controller. Redefine that, and you’re good to go:
go from model to associated table name and back · Aug 31, 2006
Given a table object, it returns the related string object; e.g.
SubAttribute => 'sub-attribute'. Useful if you want to make a list of all your tables with perhaps their fields listed out to the side.
I frequently have a collection of values that I want to match in an ActiveRecord query, but it would be nice if I could let ActiveRecord handle checking the data and escaping it properly. So, I wrote this method to return ActiveRecord-friendly conditions, such as:
["user_id=? AND job_id=?", 3, 4]
simple Rails preference storage · Aug 11, 2006
So you’ve got some Rails application and you need to store information from the users across their interactions with the app. Here’s a simple, straightforward way to do that.
custom shapes in Photoshop · Aug 3, 2006
Custom shapes can be very useful for making multiple objects that look the same. For example, say you want several photos to all be cut out of the same shape, like this:
if succinctly · Jun 7, 2006
ifis an expression, not a statement, thus it returns a value. This may not seem useful at first glance, but it lends itself to forming neat, concise code… Like most things in Ruby, actually.
the power of yield and super · May 28, 2006
The two keywords
superallow you to pass control back and forth between parent and child methods, to weave power between a more general method (in the parent class) and a more specific method (in the child class) with ease and logic. Using
supereffectively can help you maintain the DRY (Don’t repeat yourself) principle, keeping your code easier to maintain.
image generation in PHP · Mar 11, 2006
Creating images on-the-fly can be a very useful skill. Using PHP’s built-in image generation functions, it’s pretty easy, too. This tutorial will detail how to have the titles of blog entries show up as automatically generated images.
ad blocking through /etc/hosts · Mar 4, 2006
There are several ad sites that you’ll see being used everywhere. They slow down page loading, even on fast connections, because sometimes there’ll be lag and they won’t load immediately and instead of being able to read that interesting news article, you’re stuck waiting for some Flash animation to show up so you can ignore it. A simple way to make those ads 1) not show up and 2) not cause delays in page loading is to edit /etc/hosts. Check out hostsfile.mine.nu for ways of doing this in Windows and Mac.