我正在尝试向 Rails 脚手架控制器发送一个 POST 请求,该控制器包含一个嵌套数组,表示需要创建并与新创建的父级关联的记录。
下面是一些 JSON 示例:
{
"plan_id":3,
"weight":60,
"exercise_sets": [
{
"created_at":"2012-06-13T14:55:57Z",
"ended_at":"2012-06-13T14:55:57Z",
"weight":"80.0",
"repetitions":10,
"exercise_id":1
}
]
}
..和我的模型..
class Session < ActiveRecord::Base
has_many :exercise_sets, :dependent => :destroy
has_many :exercises, :through => :exercise_sets
end
class ExerciseSet < ActiveRecord::Base
belongs_to :exercise
belongs_to :session
end
我正在尝试的可能吗?