Ruby on rails 设计注册确认书

Ruby on rails 设计注册确认书,ruby-on-rails,ruby,rubygems,Ruby On Rails,Ruby,Rubygems,我在我的项目中有一个用户和一个管理员角色。我用Desive创建了身份验证 在我的管理员角色中,我没有任何确认。在我的用户模型中,我有以下内容: devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable, :timeoutable, :registerable # Setup accessible (or protected) attri

我在我的项目中有一个用户和一个管理员角色。我用Desive创建了身份验证

在我的管理员角色中,我没有任何确认。在我的用户模型中,我有以下内容:

devise :database_authenticatable, :confirmable, :recoverable,
       :rememberable, :trackable, :validatable, :timeoutable, :registerable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :username, :prename, :surname, :phone, :street, :number, :location,
                :password, :password_confirmation
我的迁移看起来像:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.confirmable
      t.recoverable
      t.rememberable
      t.trackable
      t.timeoutable
      t.validateable
      t.string  :username
      t.string  :prename
      t.string  :surname
      t.string  :phone
      t.string  :street
      t.integer :number
      t.string  :location

      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :confirmation_token,   :unique => true
    add_index :users, :reset_password_token, :unique => true
    add_index :users, :username,             :unique => true
    add_index :users, :prename,              :unique => false
    add_index :users, :surname,              :unique => false
    add_index :users, :phone,                :unique => false
    add_index :users, :street,               :unique => false
    add_index :users, :number,               :unique => false
    add_index :users, :location,             :unique => false
  end

  def self.down
    drop_table :users
  end
end
用户注册后,我将被重定向到控制器
main
,并显示“您已成功注册”的flash通知,我已登录。但是我不想登录,因为我还没有确认我的新用户帐户

如果我打开控制台,我会在日志中看到确认邮件文本,但我已经登录了。我无法解释为什么。有人有主意吗


如果我从日志中复制确认令牌并确认我的帐户,我可以登录,但如果我不确认,我也可以登录。

在config/initializers/designe.rb中有一行设置用户在被锁定之前必须确认的时间

config.confirm_within = 2.days

如果将其设置为0,则应该会得到所需的结果。

是的,就是这样!谢谢吉萨鲁我还有一个问题,也许你能帮我。我想在功能测试中测试一些东西,因此,我必须登录用户。登录帮助是好的,工作非常好,但我有问题的确认。如果我在User.make(我与机械师一起开发)中进行签名,则用户将是make,但未经确认。如果我这样做:登录User.make(:confirmation_at=>Time.now,:confirmation_sent_at=>Time.now,…)它不起作用。你知道我能做什么吗?试着用确认!user=user.make user.confirm!谢谢你,伙计!就这样!让我又过了半天不去谷歌了:)
config.confirm_within = 2.days