Does it exist? A gem or guide for storing data from such dynamic forms?
I mean I can create multiple tables for each data type, or I can store them all as TEXT, which contains the type of logo that should be converted.
UPD< /p>
Or should I better use nosql here?
Similarly, it does support all the data types you expect. It’s easy.
There is one that looks like this Collection of forms (Ruby Mongoid code)
class XForm
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid:: Paranoia
field :name, :type => String
field :user, :type => BSON::ObjectId
embeds_many :formfields
end
and
class Formfields
include Mongoid::Document
field :name, :type => String
field :kind, :type => String
#field :value, :type => String -> dont add it in formfields, make it dynamic sine the type varies
embedded_in :xform
end
To add the value field as a dynamic field, you need to enable allow_dynamic_fields:true in mongoid.yml
and create a new field like this< /p>
form = XForm.new(:name=>'test form',:user => current_user.id)
#for integer field
form.formfields << Formfields.new(:name => "Age",:kind=>"Integer", :value => 21)
#for bool field
form.formfields << Formfields.new(:name => "isMarried",:kind=>"Boolean",:value => true)
#for string field
form.formfields << Formfields.new(:name = > "name",:kind=>"String",:value => "ram")
Hope this can help
I am studying Dynamic form generator. Someone can create the following fields: string, text, boolean, number, file, etc.
Is there a gem or guide for storing data from such dynamic forms? ?
I mean I can create multiple tables for each data type, or I can store them all as TEXT, which contains the type of logo that should be converted.
UPD< /p>
Or should I better use nosql here?
I believe Mongodb is the right choice for this application because it does not enforce any patterns, it is a good choice for arbitrary data.
Similarly, it does support all the data types you expect. It’s easy.
There is a collection of forms that looks like this (Ruby Mongoid code)
class XForm
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
field :name , :type => String
field :user, :type => BSON::ObjectId
embeds_many :formfields
end
and
class Formfields
include Mongoid::Document
field :name, :type => String
field :kind, :type => String
#field :value, :type => String -> dont add it in formfields, make it dynamic sine the type varies
embedded_in :xform
end
To add the value field as a dynamic field, you need to enable allow_dynamic_fields in mongoid.yml: true
and create a new field like this
form = XForm.new(:name=>'test form',:user => current_user.id)
#for integer field
form.formfields << Formfields.new(:name => " Age",:kind=>"I nteger", :value => 21)
#for bool field
form.formfields << Formfields.new(:name => "isMarried",:kind=>"Boolean",:value => true)
#for string field
form.formfields << Formfields.new(:name => "name",:kind=>"String",:value => "ram")
Hope this helps