mongoid - 动态日期/时间属性 - 多参数异常

发布于 2024-12-24 16:04:13 字数 584 浏览 3 评论 0原文

我有一个名为 Form 的模型,它根据用户要求获取字段,例如,如果用户将文本字段放入表单中,则在表单模型中创建一个属性用于存储字符串数据。

同样,我想存储日期/时间和日期时间值。因此,我在表单模型中添加了

include Mongoid::MultiParameterAttributes

,因为日期和时间值是从多个属性中提交的。

但是我在控制器创建操作中遇到 Mongoid::MultiParameterAttributes::Errors::MultiparameterAssignmentErrors 异常,在 @form = Form.new(params[:form]) 行上

def create
  @form = Form.new(params[:form])
  if @form.save
    redirect_to(form_path(@form))
  else
    redirect_to :action => "new"
  end
end

我该如何度过这个难关。 请帮忙

I have a model named Form, which get fields as per user requirement, eg if user puts text field in the form then a attribute is created in Form model for storing string data.

Similarly I want to store date/time and datetime values. So I added

include Mongoid::MultiParameterAttributes

in the form model, because date and time values are submitted from for in multiple attributes.

But I get Mongoid::MultiParameterAttributes::Errors::MultiparameterAssignmentErrors exception in the controller create action, on the line @form = Form.new(params[:form])

def create
  @form = Form.new(params[:form])
  if @form.save
    redirect_to(form_path(@form))
  else
    redirect_to :action => "new"
  end
end

How do I get through this.
Please Help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月静好 2024-12-31 16:04:13

修改您的 Form 类,使其如下所示。

class Form
  include Mongoid::Document
  include Mongoid::MultiParameterAttributes

  ...
end

Modify your Form class so it looks like the one below.

class Form
  include Mongoid::Document
  include Mongoid::MultiParameterAttributes

  ...
end
您的好友蓝忘机已上羡 2024-12-31 16:04:13

ruby 驱动程序只能序列化 Time 对象。那可能是你的问题。

The ruby driver can only serialize Time objects. That might be your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文