レールの pinterest (オブジェクトのコレクション) でボードのようなものを実装する最良の方法は何ですか。私はそれに来ようとしていますが、それは配列の実装のようです。関連付けのロジックは次のとおりです。ユーザーには多くのコレクションがあり、ユーザーには多くのピンがあり、コレクションはユーザーに属しています。
ユーザークラス
class User < ActiveRecord::Base
has_many :pins, through: :collections
has_many :collections
end
ピンクラス
class Pin < ActiveRecord::Base
belongs_to :user
has_many :collections
end
コレクションクラス
class Collection < ActiveRecord::base
belongs_to :user
end
コレクションを作成し、このコレクションオブジェクト内でピンを作成またはプッシュし、それらを current_user の別のオブジェクトとして保存できるようにするコントローラーを実装する方法は、ここで私の混乱です。私が理にかなっていることを願っています
コントローラーはこちら
class CollectionsController < ApplicationController
def create
@collection = current_user.collections.new(params[:collection])
#this where i'm confused , if it an array , how to implement it , to push or create a pin object inside ?
end
end