1
votes

Console Error

/puppyPals console$ rake db:seed rake aborted! NameError: uninitialized constant Profile::friend /Desktop/puppyPals/puppyPals/app/models/profile.rb:8:in `follow' /Desktop/puppyPals/puppyPals/db/seeds.rb:31:in `block in ' /Desktop/puppyPals/puppyPals/db/seeds.rb:31:in `each' /Desktop/puppyPals/puppyPals/db/seeds.rb:31:in `

#app/models/profile.rb class Profile < ActiveRecord::Base has_many :friends, class_name: "friend", foreign_key: "follower_id", dependent: :destroy has_many :following, through: :friends, source: :followed

    # Follows a profile.
    def follow(other_profile)
        friends.create(followed_id: other_profile.id)
    end

    # Unfollows a user.
    def unfollow(other_profile)
        friends.find_by(followed_id: other_profile.id).destroy
    end

    # Returns true if the current user is following the other user.
    def following?(other_profile)
        following.include?(other_profile)
    end
end

#Seeds.rb
Profile.create!(first_name:  "First",
             last_name: "Last",
             dog_name:  "Dog")

99.times do |n|
    first  = "name-#{n}"
    last = "last"
    dog = "dog"
    Profile.create!(first_name: first,
                 last_name: last,
                 dog_name: dog)
end

profiles = Profile.all
profile  = profiles.first
following = profiles[2..50]
followers = profiles[3..40]
following.each { |followed| profile.follow(followed) }
followers.each { |follower| follower.follow(profile) }
1
class_name should be proper case e.g. class_name: 'Friend'engineersmnky

1 Answers

0
votes

You need to properly define your class_name for your Friend model. It should change to:

class Profile < ActiveRecord::Base
  has_many :friends, class_name:  "Friend", foreign_key: "follower_id",
        dependent:   :destroy
  # ...
end

Read more about the class_name argument here.