我在服务器上有两个模型:
喂养
class Feed < ActiveRecord::Base
attr_accessible :name
belongs_to :broadcasts
end
播送
class Broadcast < ActiveRecord::Base
validates_presence_of :content
attr_accessible :content, feeds, feeds_attributes
belongs_to :user
has_many :feeds
accepts_nested_attributes_for :feeds
def to_s
result = "id: " + id.to_s + " content: " + content
if user
result += " user: " + user.id.to_s
end
result
end
def self.per_page
8
end
end
在我的客户端上,我有用于 Broadcast 和 Feed 的基本 ActiveResource 类
当我尝试使用给定的提要(来自客户端)创建新的广播时:
feed1 = Feed.find(3) <-succesful
broadcast = Broadcast.new
broadcast.attributes['feeds_attributes'] ||= []
broadcast.feed_attributes << feed
broadcast.save
在服务器上的 BroadcastController 中,我只是做
@broadcast = Broadcast.new(params[:broadcast])
这给出了以下错误:
无法批量分配受保护的属性:Feed