@user.get_voted 评论和发布 [英] @user.get_voted comment and post

查看:44
本文介绍了@user.get_voted 评论和发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户个人资料页面上,我将显示用户这样点赞的所有评论(使用acts_as_votable_gem):

On a users profile page i am displaying all the comments that the user has upvoted like this (using the acts_as_votable_gem):

 def show
 @uservotes = @user.get_voted Comment
 end

评论都属于帖子.在视图中,我试图获得评论以及这样的评论:

Comments all belong_to a Post. In the view I am trying to get the comment as well as the comments post like this:

 <% @uservotes.each do |comment| %>

 <%= comment.post.title %>
 <%= comment.title %>

 <% end %>

它得到的 comment.title 很好,但给了我这个 comment.post.title:

It gets the comment.title fine but gives me this for the comment.post.title:

undefined method `title' for nil:NilClass

如果我这样做:

<%= comment.post %>

它返回一个id:

#<Post:0x0000010a956658>

推荐答案

commentpost 值为 nil 出现错误时.为了让任何人帮助您确定原因,您必须分享有关 get_voted 的定义/结果的信息,评论

The post value of comment is nil when the error is raised. In order for anyone to help you determine the reason for that, you'd have to share information about the definition/results of get_voted, what's in a Comment, etc.

这篇关于@user.get_voted 评论和发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆