【发布时间】:2018-03-26 18:14:35
【问题描述】:
我正在尝试使用 Accept_nested_attributes_for 保存带有任务的事件,但它不起作用。
我的模型:
class Event < ApplicationRecord
has_many :tasks
accepts_nested_attributes_for :tasks, :allow_destroy => true
end
class Task < ApplicationRecord
belongs_to :event, optional: true
end
事件参数方法
params.require(:event).permit(:name, tasks_attributes: [ :name ])
通话后
{
"name": "event",
"tasks_attributes": [
{ "name": "Task 1" }
]
}
你认为这可能是什么?
【问题讨论】: