postコントローラーのshowアクションでエラーが起きます
【超初心者です】簡単なブログ投稿機能を実装しているのですが、投稿内容を表示するときにエラーが起きます。
発生している問題・エラーメッセージ
NoMethodError in Posts#show Showing /home/ec2-user/environment/blog/app/views/posts/show.html.erb where line #2 raised: undefined method `content' for nil:NilClass Extracted source (around line #2): <div class="posts-show-item"> <%= @post.content %> #ここでエラーが出ます </div>
該当のソースコード
class PostsController < ApplicationController
def index
@posts= []
end
def create
@post = Post.new(content: params[:content])
@post.save
redirect_to("/posts/index")
end
def new
end
def edit
end
def show
@post = Post.find_by(id: params[:id])
end
def update
end
def destroy
end
end
試したこと
まだ始めたばかりで全然わかりません(T ^ T)
見よう見まねでやっているのですが・・・難しいです
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/07 13:07