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 /岗位任职。 ..虽然我希望它留在那个话题。我怎样才能正确重定向?