Using “type” in Ruby on Rails
Filed under: Galaxia, Games, MPOGs, Programming, Ruby on Rails, Technology, Web Programming
Imagine a forum system. A forum will have threads and replies. Threads and replies are different and have different functionality, but certainly share a lot of characteristics. So you might create a class message with two sub classes: replies and threads.
In Rails you can store all these in one messages table with a type field set to either reply" or thread. When you load a message it will actually create either a reply or thread object (in stead of a message object). When you create a new object it stores it in the messages table with the correct type.
This is ideal for Galaxia. In fact it's the model I used all along - I just had to write the functionality myself.
