ActiveRecordの周りに私の頭を浮かべて、関連付けを作成するのに本当の問題がありましたので、間違いは簡単です。ActiveRecordクエリのモデルには属性がありません
@user = User.joins(researchers: :students).select(user_attributes).find(current_user.id)
user_attributes = 'researchers.year, users.givenname,
...電気ショック療法:
@user
オブジェクトを持っています。
これは問題なく動作します。私は非常によく似た行を実行しようとすると:
@supervisor = User.joins(researchers: :supervisors).select(supervisor_attributes).where('supervisor.student_id = ?', 1)
私は@supervisor.surname
を呼び出すしようとすると、supervisor_attributes = 'user.surname'
はノーメソッドのエラーを取得し、私は絶対にないアイデア理由がありません。
私は数や回避策を試してみましたが、私は以下のように私のコードや団体とのより根本的なエラーがあると思う:
student.rb
class Student < ApplicationRecord
#Must have the following
validates :name, :email, :surname, :email, :supervisor, :registration_number, presence: true
#ensures unique email addresses
validates :email, uniqueness: true
#assosiations
belongs_to :researcher
end
supervisor.rb
class Supervisor < ApplicationRecord
belongs_to :researcher
end
researcher.rb
class Researcher < ApplicationRecord
#belongs_to :project
belongs_to :user
has_many :supervisors
has_many :students
end
user.rb
class User < ApplicationRecord
include EpiCas::DeviseHelper
has_many :event_registrations
has_many :events, through: :event_registrations
belongs_to :project
has_many :researchers
has_many :students, :through => :researchers
has_many :supervisors, :through => :researchers
# def self.authenticate(username)
# where(username: username).first
# end
end
すべてのヘルプは非常に高く評価されるだろう!
多くのおかげで、 ジェームズ
エラーメッセージ –