Rails 嵌套属性质量分配错误 [英] Rails Nested Attributes Mass Assignment Error
本文介绍了Rails 嵌套属性质量分配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用户模型,我无法创建客户端,因为它在批量分配中不可写.
I have a user model where I cannot create a client due to it being unwritable in mass assignment.
如何制作才能创建客户端模型?
How do I make it so that I can create a client model?
代码和错误可以在这里找到:http://pastie.org/1206482
Code and error are found here: http://pastie.org/1206482
推荐答案
我认为你必须补充:
attr_accessible :client_attributes
到您的用户模型.client_attributes 是发布到创建操作的用户哈希中的哈希.
to your user model. client_attributes is the hash in the user hash posted to the create action.
传输的哈希看起来像这样::user => { :username => "one", ..., :client_attributes => { :name => "client" } }
The transmitted hash looks something like this: :user => { :username => "one", ..., :client_attributes => { :name => "client" } }
这篇关于Rails 嵌套属性质量分配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文