0
0

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.

NameError の解決例

Posted at

NameError in Posts#edit
undefined local variable or method 'post' for #<#<class○○○
Did you mean? @post

変数postaは定義されておらずnilとなっています。postではなく@postではないか?
という内容になっています。

app/views/posts/deit.html.erb
<% form_with model:post,class::form,local:true dp |form| %>

form_withは、モデルとオプションを入力すると送信先の設定が自動でされます。
今回はpost(nilな変数)から送信先が推測できなかったことがエラー原因です。
したがってpostを@postに修正して下記の表記にします。

app/views/posts/deit.html.erb
<% form_with model:@post,class::form,local:true dp |form| %>
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?