Ruby:如何卸载设计? [英] Ruby: how to uninstall Devise?
问题描述
我已经安装了 Devise,现在想删除它,包括它生成的所有文件.我该怎么做?
I have installed Devise and now want to remove it, including all the files it has generated. How do I do that?
推荐答案
我今天正在考虑解决同样的问题,由于没有回答,试一试=)
I'm looking at solving the same problem today and since this is not answered, giving it a go =)
模型
Devise 会生成一个 User
模型.删除 devise
下的行.这就是我的样子.
Devise generates a User
model if you installed by default.
Remove the lines under devise
. This is how mine looks like.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
在attr_accessible
中,您可以删除email
、:password
、password_confirmation
和remember_me代码> 如果您不再需要它们.
In attr_accessible
, you may remove email
, :password
, password_confirmation
and remember_me
if you no longer need them.
观看次数
默认的 Devise 安装不会在您的 app
文件夹中生成视图.如果你为 Devise 生成了覆盖视图,你可以通过运行 rails destroy devise:views
(Rails 3) 来删除它们.
A default Devise install doesn't generate views in your app
folder. If you generated overriding views for Devise, you may remove them by running rails destroy devise:views
(Rails 3).
一般来说,所有的视图都存储在app/views/devise
中.
Generally, all the views are stored in app/views/devise
.
控制器
默认情况下,Devise 也不生成任何控制器.如果您进行了任何覆盖,它们很可能被称为 registrations_controller
.在您的项目中搜索继承 Devise::RegistrationsController
类的控制器.
By default, Devise doesn't generate any controllers too. If you did any overrides, they are most likely known as registrations_controller
. Search your project for controllers that inherit Devise::RegistrationsController
class.
此外,如果您遵循 Devise 的 wiki 并四处添加重定向方法等,请注意用于重定向用户的方法,例如 after_sign_in_path_for
、store_location
等.
Also, if you followed Devise's wiki and monkey-ed around to add redirect methods etc, look out for methods such as after_sign_in_path_for
, store_location
etc that are for redirecting users.
迁移
如果您通过其生成器安装了 Devise,请注意迁移 create_users
.如果您不再需要它,请在迁移中使用 drop_table :users
来摆脱它.
If you installed Devise via its generators, look out for a migration create_users
. If you don't need it anymore, use drop_table :users
in a migration to get rid of it.
我假设大多数人都希望保留他们的 User 模型.如果您使用的是设计 <2.0,迁移是由助手完成的.一旦您从 Gemfile
中删除 Devise,Rails 将无法理解下面的帮助程序并抛出错误,例如,当您尝试在另一个盒子上重新运行这些迁移时.这些助手是:
I'll assume most people would want to keep their User model. If you're using Devise < 2.0, the migrations are done by helpers. Once you remove Devise from the Gemfile
, Rails will not understand the helpers below and throw errors, for instance, when you're trying to rerun these migrations on another box. These helpers are:
t.database_authenticatable
t.recoverable
t.rememberable
t.trackable
t.encryptable
t.confirmable
t.lockable
t.token_authenticatable # => becomes t.string :authentication_token
对于确切的列,以下是Devise生成的列的参考.
For the exact columns, the below is reference to the columns generated by Devise.
https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style
上面的指南列出了 Devise 使用帮助程序生成的字段.您应该能够查看列表和模型(例如,在控制台中调用 User
),生成删除这些列的迁移.
The guide above lists the fields generated by Devise using the helpers. You should be able to look through the list and your model (e.g. calling User
in console), generate a migration that removes those columns.
但是……
有点遗憾的是,为了一致性,我们必须使用上面的指南将迁移转换为不使用帮助程序,然后生成迁移以删除它们.这是为了迁移历史的一致性,否则任何运行迁移的人都可能会尝试调用不存在的帮助程序.此外,您删除字段的迁移也将期望这些字段存在.
It's a little unfortunate that for consistency, we have to convert the migration to not use helpers using the guide above then generate a migration to remove them. This is for migration history consistency, otherwise anyone running the migrations might try to call the non-existent helpers. Also, your migration to remove the fields will also expect the fields to be present.
或者,现在可能是压缩迁移并依赖 schema.rb
/structure.sql
获取架构的最新状态的好时机.即使在删除迁移之后,您也可以随时使用 rake db:schema:load
重新创建您的开发数据库.
Alternatively, it might be a good time to squash the migrations and rely on schema.rb
/ structure.sql
for the schema's to-date state. Even after deleting migrations, you can always recreate your development DB anytime using rake db:schema:load
.
初始化程序和语言环境
删除config/initializers
中的devise.rb
和config/locales
中的devise.en.yml
.
Remove devise.rb
in config/initializers
and devise.en.yml
in config/locales
.
路线
删除任何 devise_for
行.这些将在移除 gem 后引发错误.
Remove any devise_for
lines. These will raise errors after the removal of the gem.
宝石文件
耶.所有圆顶,从您的 gemfile 中删除 gem 'devise'
行.
Yaay. All dome, remove the line gem 'devise'
from your gemfile.
这篇关于Ruby:如何卸载设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!