简体   繁体   English

迁移到Ruby on Rails中的设计

[英]Migrate to Devise in Ruby on Rails

I have an existing model that uses bcrypt to encrypt the user password. 我有一个使用bcrypt加密用户密码的现有模型。 I wonder how I could migrate to use devise? 我想知道如何才能迁移到使用devise吗? Do I still install devise the normal way and change the model attribute via database migration? 我是否仍以常规方式安装devise并通过数据库迁移来更改model属性?

Add devise to your Gemfile, run bundle install , then rails generate devise ModelName (change ModelName to actual name of your model). 将devise添加到您的Gemfile中,运行bundle install ,然后rails generate devise ModelName devise rails generate devise ModelName (将ModelName更改为模型的实际名称)。 This should add all needed things to your model as well as create a migration. 这应该将所有需要的东西添加到模型中,并创建迁移。 I think devise will know, that your model already exists and it won't try to create new table, but it will modify existing one instead. 我想devise会知道,您的模型已经存在,并且不会尝试创建新表,但是它将修改现有的表。 Then just run rake db:migrate , restart server and you should be good to go. 然后只需运行rake db:migrate ,然后重新启动服务器即可,您应该一切顺利。

Just to be sure, use git or some other versioning system. 只是要确保使用git或其他版本控制系统。 It's been a while since I last tried this, so make sure you can easily go back, if something goes wrong. 自上次尝试以来已经有一段时间了,因此,如果出现问题,请确保您可以轻松返回。

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

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