Topic: STI options for has_many :through
I am building a simple intranet application for a printing company and am a little stuck on strategy.
class Job < ActiveRecord::Base
# t.column :name, :created_at, :due_on, :notes, :etc
has_many :options, :through => :job_options
Now an option could be either paper stock, quantity, ink, etc. They are all basically string fields held inside of various select lists, so I figure "Hey this looks like a job for STI"
And thus swoops a single table to the rescue...
class Option < ActiveRecord::Base
# t.column :type, :name
class Stock < Option
class Ink < Option
class Quantity < Option
Of course I now need to create the table for my join model:
class JobOption < ActiveRecord::Base
# t.column :name, :stock_id, :quantity_id, :ink_id, :etc
belongs_to :job, :polymoprhic => true
Eventually I will need to filter my sub-options into select lists.
For example, the paper list might look like this:
- 80 lb. Cover
- 120 lb Cover
- Cotton Fiber Special
- Add New Stock
Thanks to ryanb's help in another thread I think I've got the AJAX part of this covered..
But I am at a total loss on 2 things
1. How to filter out the child classes from the parent class "Option" in order to spit out the select lists.
2. How to define the action for the creation of a new Sub-Option.
At this point I am even questioning my initial approach of has_many :through, since nothing more than the option name is defined in the selection.
Am I on the right track?