rails-api多态关联的嵌套属性

时间:2015-08-20 16:59:21

标签: ruby-on-rails

我有像这样的多态关联:

class Client < ActiveRecord::Base
  belongs_to :contractable, :polymorphic => true
end

class Individual < ActiveRecord::Base
  has_many :clients, :as => :contractable
end

class Business < ActiveRecord::Base
  has_many :clients, :as => :contractable
end

如果我想向客户端(POST /clients)发送POST,当我在请求正文中发送JSON时,如何指定创建个人或业务并正确设置关联?

Ex JSON(不工作):

{
  "client": {
    "name": "Person",
    "contractable": {
      "age": 50
    }
  }
}

另外,如何告诉strong_params允许这种情况发生?

0 个答案:

没有答案