0

このエラーが発生し続けます。モデルで属性にアクセスできるようにしました。

class Contest < ActiveRecord::Base
attr_accessible  :optinpartners_attributes, :prizes_attributes, :css, :description,      :enddate, :promotion, :rules, :slug, :startdate, :title


 accepts_nested_attributes_for :optinpartners
 accepts_nested_attributes_for :prizes


  has_many :contest_entries
  has_many :contestants, :through => :contest_entries


  has_many :contest_prizes
  has_many :prizes, :through => :contest_prizes  

  has_many :contest_optins
  has_many :optinpartners, :through => :contest_optins

正確なエラーは次のとおりです。

Can't mass-assign protected attributes: prize, optininpartner


app/controllers/contests_controller.rb:49:in `new'
app/controllers/contests_controller.rb:49:in `create'

私の理解によると、属性がモデルでアクセス可能になっている場合、これは問題になりません。しかし、大量割り当てはセキュリティ上の脆弱性でもあります。セキュリティを犠牲にせずにこれを修正するにはどうすればよいでしょうか?

編集: 要求どおり: これはコンテスト用の _form.erb.html ファイルです。このスニペットは賞品とオプトイン用です

<h2> Enter information on prizes </h2>

<%= f.fields_for :prize do |builder| %>

<%= builder.label :prize, "Prize" %><br/>
 <%= builder.text_field :prize%><br/>
<br/>
<%= builder.label :description, "Description" %>
<%= builder.text_field :description%>


<%end%>
<hr>

<hr>
<h2> Enter information on Opt-In Partners </h2>

<%= f.fields_for :optinpartner do |builder| %>

<%= builder.label :name, "Name of Partner" %> 
<%= builder.text_field :name%>

<%end%>
<hr>
4

1 に答える 1

0

attr_accessible の複数形の :optinpartners_attributes、:prizes_attributes の代わりに、単数形 (:optionpartner_attributes および :prize_attributes) を使用します。

attr_accessible  :optinpartner_attributes, :prize_attributes, :css, :description,      :enddate, :promotion, :rules, :slug, :startdate, :title
于 2013-05-01T15:21:38.407 に答える