作成時に cardpacks_controller で呼び出される 15 枚のカードのランダム パックを作成したいと考えています。私は次のモデルを持っています:
カード:
class Card < ActiveRecord::Base
# relations
has_many :cardpacks, through: :cardpackcards
belongs_to :cardset
end
カードパック:
class Cardpack < ActiveRecord::Base
#relations
has_many :cards, through: :cardpackcards
belongs_to :cardset
# accept attributes
accepts_nested_attributes_for :cards
end
カードパックカード:
class Cardpackcard < ActiveRecord::Base
#relations
belongs_to :card
belongs_to :cardpack
end
カードセット:
class Cardset < ActiveRecord::Base
#relations
has_many :cards
has_many :cardsets
end
ランダムな card_id 値と同じ cardpack_id を持つ 15 個の Cardpackcards レコードを作成するにはどうすればよいですか (これらは同じパックに属します)
複雑なフォーム シリーズのチュートリアルを見たことがありますが、この問題に取り組む方法がわかりません。
誰かがこの問題を解決するのを手伝ってくれて、Rails 言語についてより多くの洞察を与えてくれることを願っています。
ありがとう、エリック