69
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】param is missing or the value is empty:について

Posted at

#問題箇所のコード

controller.rb
  def create
    @collect = Collect.create(collect_params)
    if @collect.save
      redirect_to "/group/show/#{@collect.group_id}"
    else
      render "new"
    end
  end
(省略)
  private
  def collect_params
    params.require(:collect).permit(:url, :group_id)
  end

主にcollect_paramsが悪いはず。

#param is missing or the value is empty:
意味は単純にparamsが存在しないか空ですとなる。

パラメータを確認するとこんな感じ。ちゃんと情報渡せてるように見えるけどfalseになってる。

<ActionController::Parameters {"authenticity_token"=>"Ze5qfbN7z11+vpQ0BRGuCOV8U6m9e/aH6B7QuXFkJ13sXD66fpls3yxpB8fxymNI3XqOR6KiBmemdPRC++aVTw==", "url"=>"https://(省略)", "group_id"=>"5", "commit"=>"Save ", "controller"=>"collect", "action"=>"create"} permitted: false>

#原因
params.require(:collect)の部分が不要なんだと思う。
(もともとCollectテーブルに保存されるものとして送信されているのに、params.require(:collect)と書くとだぶるのかなあ)

#解決

controller.rb
  private
  def collect_params
    params.permit(:url, :group_id)
  end

params.require(:collect)を削除した。参考は下記のURL

69
50
1

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
69
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?