加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 未定义的方法`email’for#

发布时间:2020-12-17 02:32:30 所属栏目:百科 来源:网络整理
导读:无法弄清楚这里有什么问题.跟着Devise设置说明,用Google搜索我能想到的一切,仍然没有运气. undefined method `email' for #User id: nil,created_at: nil,updated_at: nilExtracted source (around line #7):4: %= devise_error_messages! %5: 6: div%= f.la
无法弄清楚这里有什么问题.跟着Devise设置说明,用Google搜索我能想到的一切,仍然没有运气.

undefined method `email' for #<User id: nil,created_at: nil,updated_at: nil>
Extracted source (around line #7):

4:   <%= devise_error_messages! %>
5: 
6:   <div><%= f.label :email %><br />
7:   <%= f.email_field :email %></div>
8: 
9:   <div><%= f.label :password %><br />
10:   <%= f.password_field :password %></div>

这是我的用户模型:

class User < ActiveRecord::Base
  rolify
  # Include default devise modules. Others available are:
  # :token_authenticatable,:confirmable,# :lockable,:timeoutable and :omniauthable
  devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email,:password,:password_confirmation,:remember_me

  validates_presence_of :email
  validates_uniqueness_of :email,:case_sensitive => false

end

我运行rake db:migrate,重置服务器,你有什么.仍然无法弄清楚我哪里出错了.我甚至有另一个基本的应用程序与相同的设置,梳理源,似乎我已经做了一切正确,只是看不到问题.

解决方法

基本上,您的错误意味着您的用户模型中没有电子邮件列(或attr_accessor).

我想你用的是Devise< 2.0现在您使用的是最新版本. 从2.0开始,Devise不再自动将列添加到模型中,see this page for more info.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读