您好我正在浏览Ruby on Rails指南的最后一章,我似乎无法弄清楚我目前遇到的问题。这是输入此特定代码后我的localhost / home页面中的输出:@user.followed_users.count
2: <div class="stats">
3: <a href="<%= following_user_path(@user) %>">
4: <strong id="following" class="stat">
5: <%= @user.followed_users.count %>
6: </strong>
7: following
8: </a>
这是我收到的错误。
app/views/shared/_stats.html.erb:5:in
app/views/static_pages/home.html.erb:8:in
但问题是,当我删除代码@user.followed_users.count
时它完美无缺,但我无法看到我的跟随计数(就像在推特中),这不是指南的一部分..而且是部分类似Twitter的应用程序。
这是两个文件的全部要点,我希望有人可以帮忙解决这个问题。
https://gist.github.com/2866551
非常感谢任何帮助。 -Marc
答案 0 :(得分:1)
您在用户模型中的关系应该与has_many :followed_users, through: :relationships, source: :followed
类似,而不是has_many :followed_users, through: :relationships, source: "followed_id"
您进行此更改它将正常工作。