Search code examples
ruby-on-railsformsclass-table-inheritance

Handling forms with class table inheritance models


I would like to use form_for except I have class table inheritance models using the citier gem. They are defined as such:

class Fruit < ActiveRecord::Base
    # calories:integer
    # color:string
end 

class Apple < Fruit
    # is_sauce:boolean
end

class Banana < Fruit
    # is_peeled:boolean
end

The problem is that I want the first part of my form to fill out attributes for my Fruit model. Then depending on a select field on what type of fruit (Apple, Banana), I then want to fill out attributes for that particular model yet I still want validations with the form_for helper. Any suggestions on how I can approach this... or additional clarification? Thanks.


Solution

  • What I ended up doing was asking for the model before creating the form. Then using many partials.