Monthly Archives: September 2006

Loading Fixtures in a Migration

I love migrations I think they are one of the best things about rails. I love that I can count on any changes I’ve done in the database to be consistent across all other databases that I use. Love it.

Sometimes I find that I want pre-load my database with some data, like categories that I have. For testing purposes, I have already created this data in my fixture; now I just want to load that fixture into my database from a migration call.

I know that there is a rake task for this, so I looked into that code and came up with a little something.

Continue reading

Sleeping Easier with Migrations

As a rails user who loves migrations, I have noticed that all of the migrations are prefixed with three decimal places, like 001_create_sessions.rb or something of that nature. That got me thinking, what would happen after I had 999 migrations?

That sets of the paranoia level up because who knows, I may need 1001 migrations! So to settle this once and for all, I wrote a script that would generate 999 migrations for me. I ran the 1000 migration and then it created 1001_test1001.rb.

Good news! Rails doesn’t constrain its migrations to a 3 decimal place prefix. So pointless…

Opening a directory in TextMate from Finder

I love TextMate. I love being able to load in a directory as a project, like I do with a lot of my rails applications. When I’m using Finder to navigate my filesystem, I sometimes want to open a directory into TextMate from Finder, and a contextual menu would be perfect.

Using some knowledge of Automator, this can be done quite easily.

Continue reading

Simply Restful Backport

I desperately want to use edge rails to have all the goodies of Rails 1.2, especially the RESTful stuff. The problem is that it’s bleeding edge and I am working on a project that will be public and not for my own desires.

There is a simply_restful plugin available, which is what Rails 1.2 will be modeled after. The problem is that there will be differences between the plugin and the rails source. That means after using one, I have to refactor some code to include conventions like change my delete methods to destroy and some pluralizing stuff as well.

That’s where the simply_restful_backport plugin comes in. The author has made a plugin which implements the RESTful stuff as it will be in Rails 1.2. I am going to try it out this weekend and see how she fits.

I heart Ruby: Metaprogramming

So today I had an interesting problem. For whatever the reason, I wanted to have a class automagically be created. It was going to be a helper model, and I didn’t feel like having umteen classes that all did the same thing, just had different names for different tables. My solution: use the power of ruby and metaprogramming

def create_new_active_record_model(class_name)
  klass = Class.new(ActiveRecord::Base) do
    belongs_to :old, :class_name => class_name
    def some_method_you_want
      "something"
    end
  end
  Object.const_set "#{class_name}Target", klass
end

I know that some of this could have been encapsulated in a polymorphic association but this allows you to do something beyond just keeping everything in one table, like with polymorphic associations.

Continue reading

Previewing Beast: the open source Rails forum

Beast is a nice, light-weight forum written in Rails. From what I can gather, the overall goal is to make something work with only 500 lines of code, and I think that could happen with this. It is open source, and can easily be checked out

I did check it out and I have to say that I’m impressed. It is using the rails edge and is trying out some of the REST(representational state transfer)ful stuff all the while adhering to the philosophies of CRUD(create, read, update, delete). I have wanted to look into a good example of a rails project using REST, and this code base is great for that. What’s more is that it’s not very difficult to wrap your head around all of the code of the site, due to the small code base and nice abstraction of the code.

Continue reading

Google Image Labeler

Google has released another beta product called Google Image Labeler The premise is you and a random partner have 90 seconds to get a match on as many pictures as you can. A match is a label or tag that you give to the image is the same as one your partner has given. So it’s a little game you can play in your off-time, and if you sign in, you can use a display name.

This is just genius. By creating a game out of it, Google is having the users of the internet help them find better ways for users to search for images. The other brilliant part is that it only lasts 90 seconds, so you are forced to think quick, and thus you have more of a stream of conscious going on and you are less likly to filter your response.

Getting Real Review

I have come across the works of Pete Wright as I have come to know him somewhat. He does a lot of agile and XP(eXtreme Programming) development, and that is something that I have been wanting to learn more about. While reading through his blog, he mentioned a book, Getting Real so I had to take a look and review it over.

The book is a publication from the fine folks at 37signals and brings to light some of their coding philosophies, such as how they do agile development. It is a cheap book and you can achieve instant gratification from purchasing it online because the book is currently only available as a PDF download. The voice of the book takes a stand and casts a very bright light in order to bring out the contrast of other methods of software development and project management. The authors like to shock you up a bit by making claims of saying “no” to your customers or saying “no” to project meetings. It’s like a cold shower for your brain, and once it has gotten its attention, it reasons with you as to why you would want to say no in certain situations and why you would want to say yes.

Continue reading