无法批量分配受保护的属性:来宾,付款

时间:2013-02-06 05:04:52

标签: ruby-on-rails

class Offer < ActiveRecord::Base
attr_accessible :name, :admin_id, :guest, :depart, :return, :adult, :kid
attr_accessible :guests_attributes, :payments_attributes
has_many :guests, :dependent => :destroy
has_many :payments, :dependent => :destroy
belongs_to :admin
accepts_nested_attributes_for :guests 
accepts_nested_attributes_for :payments

end

在控制器中

class PaymentController < ApplicationController

def new

@offer=Offer.new
@guest = @offer.guests.build
@payment=@offer.payments.build

end

我在model.Satll中添加了guests_attributes,payments_attributes。我收到此错误。 有谁可以帮助我?

1 个答案:

答案 0 :(得分:2)

听起来您的表单或JSON / XML正在使用键guestspayments发送嵌套对象,但它们必须是guests_attributespayments_attributes。不过,看起来模型配置正确。

RailsCast可能会有所帮助。