1
私はこのフォームを提出しようとすると、このエラーWARNING: Can't mass-assign protected attributes: sub_category
を取得しました。正しいトラックが、何らかの理由で私はまだ同じエラーが発生していますが、何が間違っていますか?私はすべての情報を以下に含めました。私は警告を受け取りました "保護された属性を一括割り当てできません"
ビュー/フォーム
<%= 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
私は、ネストされたフィールド名がが消えsub_categoriesする変更されたとき、私は、その方法を試してみました。 – katie
'' '@ ip.sub_categories.build'''をレンダリングする前にフォーム –
ごめんなさい。私の間違いだった – katie