Topic: Multiple Classes or IF in View

Hi all,

I have a qeustion in regard to the design of some classes. I have the following Situation:

I write a server admin backend. So I have Hardware servers and Virtual Servers. A few columns (or fields) are used for both Server types (like hostname, ip-address, ...) but some other fields are only used for One of the server types ( like billing information for the hardware servers or parent-id for the virtual servers.

So how should l approach this? In normal (Java :-) ) I would use three different classes and two different views. Any good hint for Rails?

Is it a good idea to use One-to-One associations for this? Or three classes?

Kind Regards
Christian

Re: Multiple Classes or IF in View

It is not clear enough, the design depends on other relations to be implemented as well. As far as I got you, you can try STI (single table inheritance), see Rails API for more details as well as Rails guides for other solutions.

Re: Multiple Classes or IF in View

Thank you for your feedback. Just this morning I discovered that STI would be the solution for my situation. :-)

So my migration for server looks like:

      # General Information
      t.string :hostname
      t.integer :customer_id
      t.string :project_description
      
      # Virtual
      t.integer :server_id

      # Hardware
      t.string :os
      t.string :cpu
      t.string :ram
      t.string :raid_controller
      t.string :disk_space
      t.date    :purchase_date
      t.string  :vendor_description
      t.float   :price
      t.string  :booking_status
      t.string  :inventory_number      
      t.string :provider
      t.string :location
      t.string :rack
      t.string :server_contract
      t.string :traffic_contract
      
      # Type for STI
      t.string :type
      
      t.timestamps

On this I put two models:

VirtualServer < Server
HardwareServer < Server

We will see how this work... :-)

Christian