1
当我尝试提交下面的表单时,我得到这个错误WARNING: Can't mass-assign protected attributes: sub_category
。我曾试着在上一次询问相关问题上stackoverflow和似乎我在正确的轨道,但由于某种原因,我仍然得到同样的错误,我做错了什么?我已经包括了下面的所有信息,提前谢谢。我收到警告“不能批量分配受保护的属性”
查看/形式
<%= form_for @ip ,:url=>{:action =>"create"} do |f| %>
<%=f.text_field :email %>
<% f.text_field :ip_address %>
<%= f.fields_for :sub_category do |s| %>
<%=s.text_field :name%>
<%end%>
<%=f.submit "submit" %>
<%end%>
控制器
def create
@ips=Ip.new(params[:ip])
@[email protected]_categories.build
if @ip.save
redirect_to :controller=>"home" ,:action=>"index"
else
render 'index'
end
模型
class Ip < ActiveRecord::Base
has_many :sub_categories ,:through=>:ip_subs
has_many :ip_subs
accepts_nested_attributes_for :sub_categories
attr_accessible :sub_categories_attributes,:ip_address,:email,:ip_count
end
class SubCategory < ActiveRecord::Base
has_many :ip ,:through=>:ip_subs
has_many :ip_subs
end
class IpSub < ActiveRecord::Base
belongs_to :ip
belongs_to :sub_category
end
我想这样一来,当我改变 - 行业标准嵌套字段名称虽然消失。 – katie 2012-04-25 19:50:32
'''@ ip.sub_categories.build'''呈现表格之前 – 2012-04-25 19:52:03
抱歉,这是我的错误 – katie 2012-04-25 20:06:35