Ruby on rails 3 Rails-与API的关联

Ruby on rails 3 Rails-与API的关联,ruby-on-rails-3,associations,Ruby On Rails 3,Associations,我正在Rails中开发API,遇到了麻烦。我想我错过了一些愚蠢的事情,但我看不到 我无法在item.json中传递关联以创建关联。我以为Rails会把这些连接起来。帐户的关系需要这样固定: 项目1.rb: belongs_to :expense_account, class_name: "Account" belongs_to :income_account, class_name: "Account" account.rb: has_many :items, inverse_of: :ex

我正在Rails中开发API,遇到了麻烦。我想我错过了一些愚蠢的事情,但我看不到


我无法在item.json中传递关联以创建关联。我以为Rails会把这些连接起来。

帐户的关系需要这样固定:

项目1.rb:

belongs_to :expense_account, class_name: "Account"
belongs_to :income_account, class_name: "Account"
account.rb:

has_many :items, inverse_of: :expense_account
has_many :items, inverse_of: :income_account

账户的关系需要如下固定:

项目1.rb:

belongs_to :expense_account, class_name: "Account"
belongs_to :income_account, class_name: "Account"
account.rb:

has_many :items, inverse_of: :expense_account
has_many :items, inverse_of: :income_account