尽管在 attr_accessible 中指定,但无法以嵌套形式批量分配属性
所以我有几个模型用户和回忆录。
User.rb
has_many :memoirs
accepts_nested_attributes_for :memoirs
attr_accessible :email, :password, :password_confirmation, :memoir_attributes
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
和 Memoir.rb
belongs_to :user
attr_accessible :user_id, :content, :birth, :death, :name, :subdomain
validates_uniqueness_of :subdomain
但是,当我保存(回忆录嵌套在用户表单内)时,我收到此消息,并且回忆录未保存:“警告:无法批量分配受保护的属性:回忆录”
困惑
So I have a couple models user and memoir.
User.rb
has_many :memoirs
accepts_nested_attributes_for :memoirs
attr_accessible :email, :password, :password_confirmation, :memoir_attributes
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
and Memoir.rb
belongs_to :user
attr_accessible :user_id, :content, :birth, :death, :name, :subdomain
validates_uniqueness_of :subdomain
However when I save (the memoir is nested inside the user form) I get this message and the memoir doesn't save: "WARNING: Can't mass-assign protected attributes: memoir"
Confused
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你已经
并且
肯定
应该是吗
?
如果我有错误,请检查您的日志文件。这应该告诉你问题是什么
You have
and
So surely
Should be
?
If I have that wrong then check your log file. That should tell you what the issue is