マイグレーションに記入した
class CreatePrototypes < ActiveRecord::Migration[7.0]
def change
create_table :prototypes do |t|
t.string :title
t.text :catch_copy
t.text :concept
t.references :user, null:false, foreign_key: true
t.timestamps
end
end
end
上記の通り t.references :user, null:false, foreign_key: true
を記述すると
ストロングパラメーターにmerge
を付けることを忘れずにする!!これをせずにいるとうまく遷移できなかった。
具体的に
private
def prototype_params
params.require(:photo).permit(:title, :catch_copy, :concept, :image).merge(user_id: current_user.id)
end