I have some ideas for web apps. Sadly, I have very little knowledge of web development. So, I have decided to teach myself by building a “real word” example by in the form of an asset/ticket tracker after completing the Ruby on Rails Tutorial by Michael Hartl. I chose this kind of application because it is something that I am familiar with, so I already have an idea of how it should function. Such a system will also require me to use many of the features of Rails as I add features to my own application.
However, I have a few questions about modeling:
Computers, printers, monitors, cell phones are all a type of asset, so they would all share some fields (date purchased, purchase price, warranty length, notes), but they would also have some type specific fields based upon the type of asset. Looking from a strictly OOP perspective, I’d like to “sub class” it. How should I do this in Rails?
I want to randomly generate a asset and ticket numbers; should I use that number as the item’s primary key, or is that bad practice? My thought in doing so would be to create simple, useful CRUD URLs.
It’s too bad that I can only award one check per “question”; I guess I’ll choose the best overall answer. Any insights are appreciated.
You’re basically looking for
Single Table InheritanceakaSTI, see reference here:http://api.rubyonrails.org/classes/ActiveRecord/Base.html
In a nutshell:
In your case, every device would inherit from an Asset model.