写真モデルと製品モデルがあります。
製品コントローラーの作成アクションで、関連付けられていないすべての写真を見つけて、現在の製品に接続したいと考えています。製品IDがnilである現在のユーザーに属するすべての写真を見つけようとしています。
次に、写真ごとに製品 ID を @product.id に設定します。
私は何をすべきか?
def create
@product = current_user.products.create(params[:product])
if @product.save
render "show", notice: "Product created!"
# code here
else
render "new", error: "Error submitting product"
end
end
def current_user
@current_user ||= User.find_by_auth_token(cookies[:auth_token])
end
schema.rb
create_table "photos", :force => true do |t|
t.integer "product_id"
t.integer "user_id"
end
create_table "products", :force => true do |t|
t.string "name"
t.integer "user_id"
end