2012-12-05 63 views
0

enter image description here嵌套资源悲伤路径呈现空白评论

我有一个评论资源嵌套在帖子资源。

def create 
    @post = Post.find(params[:post_id]) 
    @comment = @post.comments.build(params[:comment]) 
    @comment.ip = request.remote_ip 
    if @comment.save 
     redirect_to post_path(@post, notice: "Comment was successfully created") 
    else 
     flash[:alert] = "Comment could not be created" 
     render 'posts/show' 
    end 
    end 

这一切工作不够好,但我有一个唠叨项目时与评论形式的职位/显示页面重新呈现,它表明,未通过验证的内联注释。我想知道正确的方法来做到这一点,短视图层中的一些逻辑,不显示未保存的评论。

回答

0

我结束了在视图中解决它,因为我无法找到任何其他解决方案

<% @post.comments.each do |c| %> 
    <% unless c.new_record? %> 
    <strong><%= "#{c.name} wrote: " %></strong><br /> 
    <blockquote><%= c.body %></blockquote> 
    <% end %> 
<% end %>