【问题标题】:Rails 3 + Devise error in migration: undefined method timeoutableRails 3 + 迁移中的设计错误:未定义的方法可超时
【发布时间】:2011-06-24 16:02:56
【问题描述】:

我在我的应用程序中使用 rails 3 和 Devise 1.3.4 进行身份验证。 生成用户模型后,我尝试将更多设计模块添加到我的 devise_create_users.rb 迁移文件,但出现错误:
ActiveRecord::ConnectionAdapters::TableDefinition 的未定义方法 `timeoutable'。

但是,添加其他模块,例如 :confirmable 就可以了。

devise_create_user.rb:

create_table(:users) do |t|
  t.database_authenticatable :null => false
  t.recoverable
  t.rememberable
  t.trackable
  t.timeoutable
  # t.encryptable
  t.confirmable
  # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
  # t.token_authenticatable


  t.timestamps
end

我的用户模型:

class User < ActiveRecord::Base

# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable, :confirmable , :timeoutable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end

任何想法可能是什么错误?

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    答案是您实际上不需要任何可超时的迁移,它只是用户/资源类的声明。看 How do I add Devise's 'timeoutable' module to an existing Devise install? - Rails 3.1

    【讨论】:

      【解决方案2】:

      执行 'rails g devise:install' 而不是 'rails g devise install' 然后迁移 db 然后它应该可以工作

      【讨论】:

        【解决方案3】:

        您是否在第一次运行后编辑了迁移文件? 您能否确保 users 表包含 devise_create_user.rb 中指定的所有列

        【讨论】:

        • 您好 Arun,我在运行任何迁移之前编辑了文件。在我收到超时错误后,我注释掉了该行并再次运行迁移。这次它成功了,我的表包含以下所有列:database_authenticable、recoverable、rememberable、trackable 和confirmable。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-11
        • 2019-08-14
        • 1970-01-01
        • 2013-02-14
        • 1970-01-01
        • 2013-12-12
        • 2017-04-19
        相关资源
        最近更新 更多