0

我收到此错误:

“ActiveModel::MassAssignmentSecurity::DaysController#create 中的错误

无法批量分配受保护的属性:_destroy”

我什至不知道 _destroy 是一个属性!

我在做什么:

我的模型是我有很多“天”的“旅行”

在我的 Trips 模型的“显示”视图中,我正在渲染表单的部分内容以添加新的“日”:

<div id="day_form">
  <%= render :partial => "day_form", :day => @day %>
</div> 

我的模型:

class Trip < ActiveRecord::Base
  attr_accessible :title, :days_attributes
  has_many :days
  accepts_nested_attributes_for :days, allow_destroy: true

end


 class Day < ActiveRecord::Base
  attr_accessible :activity_id, :order, :summary, :trip_id, :activities_attributes
  belongs_to :trip
  has_many :activities, :order => 'position'
  accepts_nested_attributes_for :activities, allow_destroy: true 
end

当我提交表单时,我收到了这个 Mass Assignment 错误。为什么?

编辑

“日”表格如下所示:

    <%= form_for(@day) do |f| %>

      <ul>
      <% @day.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

        <fieldset>
          <%= f.label :summary, "Day Summary" %><br />
          <%= f.text_area :summary, :rows => 1 %><br />
          <%= f.hidden_field :_destroy %>
              <%= link_to "remove", '#', class: "remove_fields" %>
        </fieldset>
        <div class="actions">
    <%= f.submit %>
        </div>
<% end %>
4

1 回答 1

0
 module ApplicationHelper
  def link_to_remove_fields(name, f)
    text_field_tag(:_destroy) + link_to_function(name, "remove_fields(this)")
  end

代替f.hidden_field

于 2013-06-03T15:26:55.173 回答