私はレールに不慣れで、頭を動かすことができない状況にあります。
ユーザーとウィジェットの2つのリソースがあるとしましょう。
ユーザーはウィジェットを使用できますが、ウィジェットもユーザーが作成するものであり、ウィジェットを作成したユーザーが所有する必要があります。ユーザーがウィジェットを使用し、ユーザーがウィジェットを所有している必要があります。次は私が探しているものですか?
Class User < ActiveRecord::Base
has_many :uses
has_many :widgets, :through => :uses
has_many :owns
has_many :widgets, :through => :owns
end
Class Widget < ActiveRecord::Base
has_one :own
has_many :uses
has_many :users, :through => :uses
end
Class Use < ActiveRecord::Base
belongs_to :user
belongs_to :widget
end
Class Own < ActiveRecord::Base
belongs_to :user
belongs_to :widget
end