创建具有未知领域的格式,并存储这些字段成一个序列化的提出在我的模型 [英] Creating a form with unknown fields and storing those fields into a serialized filed in my model

查看:436
本文介绍了创建具有未知领域的格式,并存储这些字段成一个序列化的提出在我的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,将有两个一组动态和已知的字段集的形式。我需要在数据库中存储动态字段的方式,我已经决定将其存储在一个序列化的领域,因为我不需要搜索的数据,而我只需要存储并在需要时调出。

I have a form that will have both a dynamic set and a known set of fields. I need a way of storing the dynamic fields in the database and I have decided on storing them in a serialized field, as I will not need to search on the data, and I just need it stored and recalled when needed.

class MyApplication < ActiveRecord::Base
    has_one :applicant
    belongs_to :member

    serialize :additional_fields, Hash

    accepts_nested_attributes_for :applicant, :additional_fields

我在想有形式返回的字段作为additional_fields_attributes并以某种方式有模特大赛storying散入additional_fields节之后。林不知道如果我尽量去当使用类似的方法缺少照顾这一点,或者我是否应该取消的accepts_nested_attributes_for和处理它在我自己的。

I was thinking of having the form return the fields as an additional_fields_attributes and somehow have the model look after storying the hash into the additional_fields section. Im not sure if I have to go as far as using something like method missing to look after this, or if I should scrap the accepts_nested_attributes_for and handle it on my own.

有没有人有什么想法?

谢谢!瑞安

推荐答案

我最终使用本教程的http://www.kalzumeus.com/2009/11/17/practical-metaprogramming-with-ruby-storing-$p$pferences/它的工作非常出色。

I ended up using this tutorial http://www.kalzumeus.com/2009/11/17/practical-metaprogramming-with-ruby-storing-preferences/ which worked really well.

感谢您的帮助!

这篇关于创建具有未知领域的格式,并存储这些字段成一个序列化的提出在我的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆