ruby-on-rails - 未定义的方法 `email' #<用户 ID : nil, created_at : nil, updated_at: nil>

标签 ruby-on-rails ruby-on-rails-3 devise

无法弄清楚这里出了什么问题。按照设计设置说明,用谷歌搜索我能想到的一切,仍然没有运气。

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,重置服务器,你有什么。仍然无法弄清楚我哪里出错了。我什至有另一个具有相同设置的基本应用程序,通过源代码梳理似乎我已经正确完成了所有操作,只是看不到问题。

最佳答案

基本上你的错误意味着你没有 email您的用户模型中的列(或 attr_accessor)。

我猜您使用的是 Devise < 2.0,现在您使用的是最新版本。

从 2.0 开始,Devise 不再自动将列包含到您的模型中,see this page for more info .

关于ruby-on-rails - 未定义的方法 `email' #<用户 ID : nil, created_at : nil, updated_at: nil>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12442674/

相关文章:

python - Ruby on Rails 是否与 Google Code API 配合得很好?

ruby-on-rails-3 - 如何在rails的后台运行rake任务

ruby-on-rails - 如何在 rspec 测试中忽略 ApplicationController 中的 rescue_from?

ruby-on-rails - 为什么我的 "rails generate devise User"和 "rails generate devise_install"给我以下错误?

ruby-on-rails - Searchkick 提升精确匹配

ruby-on-rails - 在 Rails 应用程序中同时使用 Redis 和 MongoDB

ruby-on-rails - Rails 4/设计/MongoDB : "Unpermitted parameters" using custom properties and strong parameters

ruby-on-rails - 注册失败后设计重定向

heroku - 如何清除所有设计 session ?

ruby-on-rails-3 - 使用功能测试测试设计注册 Controller