devise를 사용하고 있으며 students 대시 보드에서 current_user.email을 호출하려고합니다. 하지만 동일한 "정의되지 않은 메서드`전자 메일 'nil : NilClass"오류가 계속 발생합니다. 사용자가 아닌 경우ruby on rails "정의되지 않은 메소드`email for nil : NilClass"
학생/index.html.erb
<div class="student-index-header">
<br><%= current_user.email %></br>
<div class="student-index-header-text">
<a class="student-index-header-text-sign-out" href="<%= destroy_user_session_path %>">Sign-out</a>
</div>
</div>
student.rb
class Student < ApplicationRecord
belongs_to :user, optional: true
validates_presence_of :first_name, :last_name , :age, :description
end
user.rb
class User < ApplicationRecord
has_one :tutor
has_one :student
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
'current_user'가 정의되어 있지 않은지 확인하십시오. 로드 했습니까? 로그인이 필요하지만 로그인하지 않았을 수 있습니다. – tadman