警告:无法批量分配受保护的属性 [英] WARNING: Can't mass-assign protected attributes

查看:66
本文介绍了警告:无法批量分配受保护的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误警告:无法批量分配受保护的属性:races_attributes" ,则遵循此 http://railscasts.com/episodes/196-nested -model-form-part-1 在导轨3上.

I get this error "WARNING: Can't mass-assign protected attributes: races_attributes" , when following this http://railscasts.com/episodes/196-nested-model-form-part-1 on rails 3.

种族是事件的组成部分.这是我的模型/race.rb:

Where Races are a component of Events. This is my models/race.rb:

class Race < ActiveRecord::Base
belongs_to :event

attr_accessible :name, :unit
end

这是我的模型/event.rb:

This is my models/event.rb:

class Event < ActiveRecord::Base
has_many :races, :dependent => :destroy

accepts_nested_attributes_for :races

attr_accessible :name, :date, :description, :location_name, :address_one, :address_two, :city, :state, :zip, :active, :races_attributes
end

有什么想法吗?

推荐答案

attr_accessible指定例如,不能使用save方法批量分配属性.因此,如果更改未使用attr_accessible定义的属性,则会收到警告,因为它实际上不会保存在数据库中.

attr_accessible specifies that you can not mass-assign attributes, using save method, for example. So, if you change an attribute that is not defined with attr_accessible, you will get a warning because it will not actually be saved in the database.

这篇关于警告:无法批量分配受保护的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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