Hi I’m currently going through the last chapter of the Ruby on Rails guides and i can’t seem to figure out the problem i have at the moment. This is the output in my localhost/home page after inputting this particular code: @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>
and this is the error i receive.
app/views/shared/_stats.html.erb:5:in
app/views/static_pages/home.html.erb:8:in
but the thing is, when i remove the code @user.followed_users.count it works perfectly but i wont be able to see my following count (just like in twitter) which is not part of the guides.. and part of the twitter-like application.
Here is the whole gist of the two files and i hope someone can help out and find the solution to this problem..
https://gist.github.com/2866551
any help would be very much appreciated. -Marc
Your relationship in User model should be like this
has_many :followed_users, through: :relationships, source: :followednot thishas_many :followed_users, through: :relationships, source: "followed_id"you make this change it will work fine.