jtrinker
(Jameson Trinker)
November 5, 2013, 10:26pm
1
I just finished writing the code for Week 2 and I am getting an error when I try to follow another user that reads,
Unable to autoload constant FollowingRelationship, expected ../following_relationship.rb to define it
I’m using Rails 4 and Ruby 2.0.0-p247, I think that might be the problem. But here is a screenshot:
Any ideas? Thanks!
JoelQ
(Joel Quenneville)
November 5, 2013, 10:37pm
2
It is expecting that you have a FollowingRelationship
class defined in following_relationship.rb
but not finding it. Does that class exist there? If so, maybe you have a typo in the file name?
jtrinker
(Jameson Trinker)
November 5, 2013, 10:56pm
3
Here’s my User model and FollowingRelationship model:
class User < ActiveRecord::Base
has_many :shouts
has_many :followed_user_relationships,
foreign_key: :follower_id,
class_name: 'FollowingRelationship'
has_many :followed_users, through: :followed_user_relationships
has_many :follower_relationships,
foreign_key: :followed_user_id,
class_name: 'FollowingRelationship'
has_many :followers, through: :follower_relationships
end
class FollowingRelationShip < ActiveRecord::Base
belongs_to :follower, class_name: 'User'
belongs_to :followed_user, class_name: 'User'
end
JoelQ
(Joel Quenneville)
November 5, 2013, 11:56pm
4
You capitalized the ‘S’ in relationship. The class is named FollowingRelationShip
but your has_many
line says that it should be named FollowingRelationship
.
jtrinker
(Jameson Trinker)
November 6, 2013, 12:31am
5
Sheesh. Thanks very much. I scoured that for an hour.