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 /崗位任職。 ..雖然我希望它留在那個話題。我怎樣才能正確重定向?