【问题标题】:Generating model through Devise does not add fields - Devise with Mongoid通过 Devise 生成模型不添加字段 - Devise with Mongoid
【发布时间】:2014-09-02 09:51:01
【问题描述】:

我按照说明安装了设备。当我做rails generate devise User 时,设计确实生成了 user.rb,但它没有编写设计模块及其必填字段。 它只写在 user.rb 里面

class User
  include Mongoid::Document
end

我以前对另一个应用程序也有同样的想法,对于类似的命令,user.rb 填充了这些:

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :validatable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :omniauthable

  ## Database authenticatable
  field :email,              type: String, default: ""
  field :encrypted_password, type: String, default: ""

  ## Recoverable
  field :reset_password_token,   type: String
  field :reset_password_sent_at, type: Time

  ## Rememberable
  field :remember_created_at, type: Time

  ## Trackable
  field :sign_in_count,      type: Integer, default: 0
  field :current_sign_in_at, type: Time
  field :last_sign_in_at,    type: Time
  field :current_sign_in_ip, type: String
  field :last_sign_in_ip,    type: String

  ## Confirmable
  # field :confirmation_token,   type: String
  # field :confirmed_at,         type: Time
  # field :confirmation_sent_at, type: Time
  # field :unconfirmed_email,    type: String # Only if using reconfirmable

  ## Lockable
  # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
  # field :unlock_token,    type: String # Only if unlock strategy is :email or :both
  # field :locked_at,       type: Time

我可能做错了什么?我可能跳过了哪一步?我非常感谢您的帮助。 谢谢

【问题讨论】:

    标签: ruby-on-rails devise mongoid


    【解决方案1】:

    如果你使用的是 Rails4,

    在您的 Gemfile 中添加这一行

    gem 'devise', :git => "git://github.com/plataformatec/devise.git"
    

    然后运行,

    bundle update
    rails generate devise User
    

    现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 2011-09-10
      相关资源
      最近更新 更多