← Back to Upcase

Int. Rails Week 2: Unable to Load Constant Error


(Jameson Trinker) #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!


(Joel Quenneville) #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?


(Jameson Trinker) #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

(Joel Quenneville) #4

You capitalized the ‘S’ in relationship. The class is named FollowingRelationShip but your has_many line says that it should be named FollowingRelationship.


(Jameson Trinker) #5

Sheesh. Thanks very much. I scoured that for an hour.