LoginSignup
0
0

More than 3 years have passed since last update.

param is missing or the value is empty: というエラーが発生した時の対処法

Posted at

事象

rails にてアプリを作成中に以下のエラー発生しました。

param is missing or the value is empty: task

問題点

ストロングパラメーターに関する内容でした。このエラーの意味はparamsが存在しない、もしくは空とのことです。

requireメソッドとはパラメーターの中にモデルに対応するキーが存在するかを確認し、存在する場合にそのバリューを返します。

tasks_controller.rb
private

  def task_params
    params.require(:task).permit(:title, :description, :image)
  end

解決策

対処としてtasks_controller.rb のparams.require(:task)の箇所を削除し、以下のように修正します。これでエラーは出なくなりました。

tasks_controller.rb
private

def task_params
    params.permit(:title, :description, :image)
end

参考

参考にさせていただきました。ありがとうございました。
・【Rails】param is missing or the value is empty:について
https://qiita.com/Takka_Log/items/32dae78d7e3892e7b051

・【Rails】permitメソッドを使ってストロングパラメーターにしよう
https://pikawaka.com/rails/permit

0
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
0
0