Ruby on Rails 4 - 使用什么身份验证 gem? [英] Ruby on Rails 4 - What authentication gem to use?
问题描述
所以在过去,我们有acts_as_authenticated、restful_authentication 等......但现在除了Rails 本身具有身份验证功能之外,还有多种选择.
So in the past we had acts_as_authenticated, restful_authentication etc... But now there are a variety of options along with Rails itself having authentication functionality.
我即将开始一个新的 rails 项目,并且对每个人的偏好(对于非 oAuth)身份验证以及您建议我考虑的内容感兴趣?
I'm about to start a new rails project and am interested in what everyone's preference (for non oAuth) authentication and what you would recommend I consider?
谢谢,斯科特
推荐答案
Devise 是一种功能齐全的身份验证解决方案,可处理所有控制器逻辑和表单视图.
Devise is a full-featured authentication solution which handles all of the controller logic and form views for you.
首先,在您的 Gemfile 中包含 Devise gem:
First, include the Devise gem in your Gemfile:
gem 'devise' 'version-if-u-want-any specific'
要安装新添加的 gem,请使用:
To install the newly-added gem, use:
捆绑安装
要安装 Devise,请运行:
To install Devise, run:
rails g 设计:安装
并手动执行一些设置,这些设置显示在命令的输出中.
and perform some settings manually, which are shown in the output of the command.
(可选)出于自定义目的,我们可以在应用的视图中包含 Devise gem 的视图:
(Optional) For customization purposes, we can include the Devise gem's views in our app's views:
rails g devise:views
(可选)生成用户模型,供 Devise 使用:
(Optional) Generate the user model, which will be used by Devise:
rails g 设计用户
迁移您的数据库:
rake db:migrate
您可以使用以下方式查看路线:
You can see routes using:
rake 路线
要注册用户,请访问:
localhost:3000/users/sign_up
这篇关于Ruby on Rails 4 - 使用什么身份验证 gem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!