Я получаю следующее сообщение об ошибке при запросе домашней страницы моего примера приложения (следуя главе 11 учебника Майкла Хартла):
«ActiveRecord::HasManyThroughSourceAssociationNotFoundError in Pages#home»
«Не удалось найти исходную ассоциацию (-и) :followed_id в модели Relationship. Попробуйте 'has_many :followed_users, :through => :relationships, :source => '. Это одна из :follower или :followed?"
Это действительно странно, так как я точно следовал инструкциям туториала. Я даже скопировал каждый фрагмент кода.
Моя пользовательская модель (извлечение):
class User < ActiveRecord::Base
has_many :relationships, foreign_key: "follower_id", dependent: :destroy
has_many :followed_users, through: :relationships, source: "followed_id"
has_many :reverse_relationships, foreign_key: "followed_id", class_name: "Relationship", dependent: :destroy
has_many :followers, through: :reverse_relationships, source: :follower
Моя модель отношений:
class Relationship < ActiveRecord::Base
attr_accessible :followed_id
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
validates :follower_id, presence: true
validates :followed_id, presence: true
end
Мой файл миграции:
class CreateRelationships < ActiveRecord::Migration
def change
create_table :relationships do |t|
t.integer :follower_id
t.integer :followed_id
t.timestamps
end
add_index :relationships, :follower_id
add_index :relationships, :followed_id
add_index :relationships, [:follower_id, :followed_id], unique: true
end
end
Я пытался это исправить, но у меня просто не осталось ни малейшего представления, в чем может быть проблема. be (точная копия кода из учебника).