【发布时间】:2017-09-21 22:34:25
【问题描述】:
我正在使用“设计”,我想在学生仪表板中调用 current_user.email。但我不断收到相同的“nil:NilClass 的未定义方法 `email'”错误。
学生/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>
学生.rb
class Student < ApplicationRecord
belongs_to :user, optional: true
validates_presence_of :first_name, :last_name , :age, :description
end
用户.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未定义。你确定你已经加载了吗?这可能需要登录,但您尚未登录。
标签: ruby-on-rails ruby devise