0
사용자가 주제를 만들 수 있고 다른 사람이 주제에 대한 의견을 게시 할 수있는 응용 프로그램을 만들었습니다. 나는 지금 주제와 post.form 작업을 만들 수 있지만 내가 코멘트를 게시 할 때 내가각 오류에 대해 아무런 메쏘드를 얻지 못하는 이유는 무엇입니까?
NoMethodError in Posts#create
undefined method `each' for nil:NilClass
Extracted source (around line #2):
1:
2: <% for topic in @topics do %>
3: <li><%=link_to topic.title, topic_path(topic) %></li>
4:
5: <%= will_paginate @topics %>
내 게시물 컨트롤러 인 얻을 :
class PostsController < ApplicationController
before_filter :signed_in_user, only: [:create, :destroy]
before_filter :correct_user, only: :destroy
def create
@post = current_user.posts.build(params[:post])
if @post.save
flash[:success] = "Konu oluşturuldu!"
redirect_to topic_path(topic)
else
render 'static_pages/home'
end
end
def destroy
@post.destroy
redirect_to root_path
end
private
def correct_user
@post = current_user.posts.find_by_id(params[:id])
redirect_to root_path if @post.nil?
end
end
내가 그것을/게시물을 localhost로 리디렉션 게시물을 작성
. .. 나는 그 주제에 머물러 있기를 원하지만. 어떻게 올바르게 리디렉션 할 수 있습니까?