我有两个简单的模型:
class Idea << ActiveRecord::Base
has_many :tasks
# for nesting....
accepts_nested_attributes_for for :tasks
attribute_accessible :tasks_attributes
end
class Task << ActiveRecord::Base
belongs_to :idea
validates_presence_of :idea # this line is causing pain
end
我发送以下 JSON 来创建我的 IdeasController:
{
"description":"Test test test",
"tasks":[{"description":"test test test"}]
}
...我得到了验证错误。一旦我删除验证,一切都会好起来的!
有什么建议么?