views:

39

answers:

1

I'm working on building a pretty simple site mainly as an exercise in learning more about rails. You can see my rough progress at statific.com. It's working pretty much as I wanted it for keeping track of server information, but now I'd like to expand it to other things, next on the list being firewalls.

I can pretty easily duplicate all the models, views, etc.. that I have for my servers. The problem I see with that is that it isn't very DRY since most of the code would look the same, the only difference would be the attributes I have setup for firewalls would be different than for servers.

I know in plain ruby this is pretty simple, you can have a 'Product' w/ common attributes ('manufacturer', 'model') and then have children with more specific attributes. Does the same type of concept exist for rails, or am I just over thinking this?

A: 

Use STI (please don't poke me to death. I'm just kidding).

All common functionality should be moved to modules and included into different models (server, firewall, etc.) as needed. In this particular situation you could have a module Hardwareable and include it into your server and firewall models. And leave different attribute to appropriate models.

Eimantas
Thanks, I'll have to play around and see how that works. Any chance you could gimme a simple example?
mocker
Sorry, I don't have any code examples at hand, but I'm pretty sure you'll figure it out. For extra tips on this, theck this page: http://www.matthewpaulmoore.com/ruby-on-rails-code-quality-checklist
Eimantas