1
0

マイグレーションとmerge の関係性

Posted at

マイグレーションに記入した

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

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0