Ruby-on-rails 在 Rails 中为初学者创建登录名的最佳方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18292697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which is the best way to create a login in Rails for a starter?
提问by Zentaurus
I've seen there're several engines and tutorials about it, but I couldn't figure out which one could help me out in short terms. I'm just learning Rails and Ruby and my aim is to understand how it works while it can be useful in a real life event.
我已经看到有几个关于它的引擎和教程,但我无法弄清楚哪一个可以在短期内帮助我。我只是在学习 Rails 和 Ruby,我的目标是了解它是如何工作的,同时它在现实生活中很有用。
Any link or explanation about this will be kindly appreciated!
任何关于此的链接或解释将不胜感激!
回答by GMA
Other answers are recommending Devise. Devise's own documentation says:
其他答案推荐Devise。设计自己的文档说:
If you are building your first Rails application, we recommend you to notuse Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch.
如果您正在构建您的第一个 Rails 应用程序,我们建议您不要使用 Devise。设计需要对 Rails 框架有很好的理解。在这种情况下,我们建议您从头开始一个简单的身份验证系统。
I'm inclined to agree. Devise is a great engine that can create a powerful login system for you in minimal time, but if you're building an app for the purpose of learning Rails, I'd recommend following a tutorial to build your own login system so you get a deeper understanding of what's actually going on beneath the hood. You can always come back and use Devise later.
我倾向于同意。Devise 是一个很棒的引擎,可以在最短的时间内为您创建一个强大的登录系统,但是如果您正在构建一个用于学习 Rails 的应用程序,我建议您按照教程构建您自己的登录系统,以便您获得更深入地了解幕后实际发生的事情。您可以随时回来使用 Devise。
For a tutorial, I'd recommend the same book that Devise recommend, Michael Hartl's Ruby on Rails Tutorial- specifically chapters 6, 7, 8. (Well, I'd recommend the whole book, but those are the chapters that pertain to building a login system.)
对于教程,我推荐 Devise 推荐的同一本书,Michael Hartl 的Ruby on Rails 教程- 特别是第 6、7、8 章。(好吧,我推荐整本书,但这些章节与构建登录系统。)
If screencasts are more your thing, Ryan Bates's Railscast on the subject is supposed to be good although I haven't watched it myself.
如果你更喜欢截屏,Ryan Bates 关于这个主题的 Railscast 应该很好,尽管我自己没有看过。
回答by Rodrigo Zurek
a gem called devise, as simple as install it and minimal configuration
一个叫做 devise 的 gem,就像安装它和最少的配置一样简单
https://github.com/plataformatec/devise
https://github.com/plataformatec/devise
add it to gem file:
将其添加到 gem 文件中:
gemfile.rb
宝石文件
gem 'devise'
install :
安装 :
rails generate devise:install
create User model:
创建用户模型:
rails generate devise user
and here are the commands you can use:
以下是您可以使用的命令:
https://github.com/plataformatec/devise#controller-filters-and-helpers
https://github.com/plataformatec/devise#controller-filters-and-helpers

