Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialArtem Prytkov
11,932 PointsCan`t pass user_freindship tests
I have an error <#<NameError: uninitialized constant User::UserFriendship>> then testing unit/user_test.rb
Tests:
should have_many :user_friendships
test "that no error is raised then trying to accesss a friend list" do
assert_nothing_raised do
users(:artem).friends
end
end
UserFriendship model
class UserFrienship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: 'User', foreign_key: 'friend_id'
attr_accessible :user, :friend
end
User model
class User < ActiveRecord::Base
# *******
has_many :statuses
has_many :user_friendships
has_many :friends, :through => :user_friendships
# *******
2 Answers
Lisa Rossiter
3,630 PointsCan you paste in your error.
If you are using rails 4 and ruby 2 the attr_accessible is not needed. Could you paste the exact error
Lisa Rossiter
3,630 PointsYou also have a typo. The colon goes after through and no => instead you need a colon. I dont know why this has taken a month hopefully you have fixed the issue by now.
has_many :friends, :through => :user_friendships
has_many :friends, through: :user_friendships