首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails4种子失败

Rails4种子失败
EN

Stack Overflow用户
提问于 2014-05-07 17:55:18
回答 1查看 288关注 0票数 1

Windows8.1 Rails 4.1 Ruby2.0.0

这就是我的user.rb (模型)中的内容:

代码语言:javascript
复制
class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :password_expirable, :confirmable, :lockable, :timeoutable

  if :work_phone != nil
    phony_normalize :work_phone, :default_country_code => 'US'
  end
  if :mobile_phone != nil
    phony_normalize :mobile_phone, :default_country_code => 'US'
  end
  if :fax_phone != nil
    phony_normalize :fax_phone, :default_country_code => 'US'
  end
  if :other_phone != nil
    phony_normalize :other_phone, :default_country_code => 'US'
  end
  validates :first, presence: true
  validates :last, presence: true
  validates :organization, presence: true
  validates_plausible_phone :work_phone
  validates_plausible_phone :mobile_phone
  validates_plausible_phone :fax_phone
  validates_plausible_phone :other_phone
  validates :email, :email => true, presence: true, uniqueness: {case_sensitive: false}
  before_save { |user| user.email = email.downcase }
end

这就是我在我的seeds.rb中所拥有的:

代码语言:javascript
复制
user = User.new(
                :email =>'test@acme.net',
                :password =>'Vb%69Krn#',
                :password_confirmation =>'Vb%69Krn#',
                :first =>'John',
                :last =>'Doe',
                :salutation =>'Doe',
                :organization =>'Doe Test',
                :work_phone =>'555-555-5555',
                :mobile_phone =>'555-555-5555',
                :fax_phone =>'555-555-5555',
                :other_phone =>'555-555-5555',
                :address1 =>'One Main Street',
                :city =>'Anytown',
                :state =>'WA',
                :zip =>'98011',
                :role =>'admin'
                )
user.skip_confirmation!
user.save

当我执行rake db:seed时,会收到以下错误消息:

代码语言:javascript
复制
rake aborted!
NoMethodError: undefined method `password_changed_at_changed?' for #<User:0x00000005f2b458>
C:/projects/rails/doe/db/seeds.rb:27:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => db:seed   

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-07 18:26:19

这是扩展的一个问题。您已经设置了password_expirable,但是您可能没有这样做:

代码语言:javascript
复制
create_table :the_resources do |t|
  # other devise fields

  t.datetime :password_changed_at
end
add_index :the_resources, :password_changed_at

正如它在文献资料中所说的那样。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23524848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档