如何使用Devise:可记忆? [英] How to use Devise: rememberable?

查看:322
本文介绍了如何使用Devise:可记忆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Rails应用程序。

我想实施一个复选框'记住我'让用户从下次使用Devise跳过输入密码:rememberable.but我可以'弄清楚如何实现。

如果您有任何想法,请给我一些示例代码。

I'm making a Rails App.
I'd like to implement a check box 'remember me' for users to skip enter password from next time with using Devise:rememberable.but I can't figure out how to implement.
if you have any idea with this , please show me some sample code for that.

推荐答案

添加您的用户模型中的:可记忆选项

Add the :rememberable option in your User model

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,
         :validatable, :token_authenticatable, :lockable, :omniauthable

  # ...

end

创建迁移以添加 remember_created_at 用户表中的列

Create a migration to add the remember_created_at column in the table of users

class AddRememberCreatedAtToUsers < ActiveRecord::Migration
  def change
    add_column :users, :remember_created_at, :datetime
  end
end

如果您不使用Devise默认视图,请将复选框添加到您的视图中:

If you're not using the Devise default views, add the checkbox to your view:

<%= f.check_box :remember_me %> <%= f.label :remember_me %>

我认为这就是你需要的...

I think that's all you need...

这篇关于如何使用Devise:可记忆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆