简体   繁体   English

带有轨道4.0.1的未定义方法“摘要”

[英]undefined method `digest' with rails 4.0.1

I'm going through Agile Web Development With Rails 4 and have got to the point where I create a user. 我正在Agile Web Development With Rails 4进行Agile Web Development With Rails 4并且已经达到创建用户的地步。 It's being done like so: 它是这样完成的:

rails generate scaffold User name:string password:digest

But when I try to run rake db:migrate I get the following error: undefined method digest' 但是,当我尝试运行rake db:migrate ,出现以下错误: undefined method digest'

What is the cause of that and how can I fix it? 是什么原因造成的,我该如何解决? I googled that digest is a rails 4 feature, so how come it's an issue? 我在Google上搜索到digestrails 4功能,那怎么会成为问题呢?

Edit: 编辑:

The information below is not entirely correct. 以下信息并不完全正确。 It appears as if this generator feature is poorly documented, but does exist. 似乎该生成器功能的文档记录不充分,但确实存在。 Using password:digest in the generator simply creates a string column in the migration called :password_digest and adds has_secure_password to the model. 在生成器中使用password:digest可以在迁移中简单创建一个字符串列::password_digest,并将has_secure_password添加到模型中。 A tutorial on this feature can be found here . 可以在这里找到有关此功能的教程。


I see no mention of being able to define a password:digest in the Rails 4 Migrations Guide . Rails 4迁移指南中,我没有提到能够定义密码:摘要。 Nor do I see it in the actual Rails 4 stable source . 在实际的Rails 4稳定源中也看不到它。

You are correct that this page mentions it as being something you can do, however, it appears as if this feature either got dropped or has not made it into Rails 4 stable yet. 您是正确的, 此页面将其提及为您可以做的事情,但是,似乎该功能已被删除或尚未使其稳定在Rails 4中。

As far as fixing it, it appears that in Rails 4 stable these are the fields you can define with a migration: 就其修复而言,看来在Rails 4 stable中,这些是您可以通过迁移定义的字段:

t.column
t.index
t.rename_index
t.timestamps
t.change
t.change_default
t.rename
t.references
t.belongs_to
t.string
t.text
t.integer
t.float
t.decimal
t.datetime
t.timestamp
t.time
t.date
t.binary
t.boolean
t.remove
t.remove_references
t.remove_belongs_to
t.remove_index
t.remove_timestamps

You will probably have to store the password as a string (but don't mistake this as me saying "store the plain text password as a string" (!) ... you still want to at least hash it and probably salt it.) This video should provide a lot of help with doing this in Rails: Authentication in Rails . 您可能必须将密码存储为字符串(但是请不要误以为我说“将纯文本密码存储为字符串”(!))……您仍然希望至少对其进行散列并加盐。 )该视频应该在Rails中提供很多帮助:Rails中的Authentication

Authentication is a complex issue, and may require some research to do it properly, but it will be well worth it. 身份验证是一个复杂的问题,可能需要进行一些研究才能正确进行,但是这将是值得的。 I would highly recommend first watching that video and getting a basic understanding of user auth in Rails, and then possibly looking into some hardened gems that you can use. 我强烈建议您首先观看该视频,并对Rails中的用户身份验证有一个基本的了解,然后可能会研究一些可以使用的硬化宝石。 Using an existing gem has both the benefit of being fully-featured and also being battle-hardened by the open source community. 使用现有的gem既具有功能齐全的优势,也可以被开源社区进行艰苦的战斗。 If you find the right gem that fits your needs and is well reviewed and actively maintained, it will usually be better than what you can build yourself. 如果您找到适合您的需求的宝石,并且经过了良好的审查和积极维护,通常它会比您自己制造的宝石更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM