简体   繁体   English

您如何在Ruby on Rails中启用对Mongoid的批量分配?

[英]How do you enable mass assignments for mongoid in Ruby on Rails?

Normally you would use something like attr_accessible :name, :email to allow for mass assignment for those specific fields but how do you do this in mongoid for an embedded document like :nick_names ? 通常,您会使用attr_accessible :name, :email类的东西来允许对这些特定字段进行批量分配,但是对于诸如:nick_names这样的嵌入式文档,如何在mongoid中执行此:nick_names I tried tagging it at the end of attr_accesible but it does not work. 我尝试在attr_accesible的末尾对其进行标记,但是它不起作用。

Thanks! 谢谢!

I would use a combination of criteria and update all. 我将结合使用条件并更新所有条件。 For instance: 例如:

Foo.where(country: nil).update_all(country: "USA")

http://mongoid.org/docs/querying/modification.html http://mongoid.org/docs/querying/modification.html

If you're trying to do it via a Rails update, then @apneadiving is correct in that you need to enable accept_nested_attributes_for in the parent model. 如果您尝试通过Rails更新进行此操作,那么@apneadiving是正确的,因为您需要在父模型中启用accept_nested_attributes_for

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM