LoginSignup
0
1

More than 1 year has passed since last update.

エラー日記(name error編)

Posted at

name error発生

スクリーンショット 2023-05-26 14.20.55.png

controllers/post_controllers

class PostsController < ApplicationController
  def index
    posts = Post.all
  end

  def new
    @post = Post.new                                         #controllerでデータを作りviewからブラウザ表示
  end 

  def create
    Post.create(post.params)
    redirect_to new_post_path                                 #newメソッド
  end
  
private                                                       #予期せぬところからblog_paramsを呼び出せないようにするため

  def post.params
    params.require(:post).permit(:content)                    #送られてきたデータをパラメーターで取得
  end
end

def post.paramsじゃくて、post_params?

直したら、

スクリーンショット 2023-05-26 14.28.30.png

別のエラー発生

実は、def post.paramは直したが、Post.create(post.param)を直してなかった。

直すと?

スクリーンショット 2023-05-26 14.31.49.png

直りました!

単純なミスでしたが、コード量が多くなるとこういったことが原因でも見抜きにくくなるので、気をつけたいです。

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