akula1001
akula1001

Reputation: 4636

creating models with multiple references in rails

I have a model defined as

class A < ActiveRecord::Base
  belongs_to :b
  belongs_to :c
end

How do I create a new instance of A associated with both b and c. I've got the ids for b and c.

Upvotes: 1

Views: 378

Answers (1)

jigfox
jigfox

Reputation: 18185

You can create a new instance of a like this:

A.create :b => b, :c => c

Upvotes: 2

Related Questions