activerecord - User specified dynamic model fields in Rails -
Is anyone aware of gem or a good implementation of allowing the user to add fields to a model?
Ex.
Want to add an "internal notes" field to the user contact model. In the interface they just select "new field"> "type: text"
thanks
I'm sorry I do not know of any plugin to do this. But I have an implementation suggestion.
This idea is to add the "Dynamicfilled" model, which is from the contact model. When you have a method missing in the contact model, you check that there is a dynamic field to do this.
class DynamicField & lt; ActiveRecord :: Base is_to: Contact End Class Contacts & lt; ActiveRecord :: Base has_many: dynamic_fields def method_missing (sym, * args, and block) Super Rescue area = dynamic_film_fid_by_name (CIM) starts ActiveRecord :: NoMethodError if field.nil is extended? Field.value end end
If you want to add the attribute = method (the appearance of a "=" and want to add virtual properties with updating instead, then a regex must be added Only to get the price) but you already have ideas.
When the method does not exist, we check the dynamic field, if there is anybody with the same name (if not. Field), then we increase no methiar error. Otherwise, we return it
So you can get a list of all your areas with:
contact.find (: first) .dynamic_fields
and get a specific with the following:
contact.find (: first) .my_dynamic_field
Comments
Post a Comment