ruby - Rails 3: User Created custom forms? -
i trying wrap head around how allow user create custom forms field types. if there gem great, cannot seem find 1 anywhere.
so have db setup which:
t.integer :form_id t.string :name t.string :hint t.integer :position t.string :field_type t.boolean :required t.integer :size t.boolean :multiple t.text :values t.timestamps
and pretty am. cant think of how iterate thru field_type , return values, associate them forms being filled out.
thanks
i assume have kind of form
model, , kind of field
model, , form has_many :fields
. correct?
building form quite straightforward: retrieve form, iterate on fields, , depending on type, render correct code. if use formtastic or simple_form code pretty straightforward.
but make work, inside controller have create dummy object, has getter , setter fields. use simple hash this, or openstruct (better). while iterating on fields set hash empty or default values.
i think want save results of form? think easiest way use model this
t.form_id :integer t.fields_data :text
and store entered data in text-field in e.g. json or something.
class formdata belongs_to :form end class formdatafield belongs_to :form_data belongs_to :form_field end
while cleanest (you can query on values of filled in fields form), maybe of overhead.
Comments
Post a Comment