Ruby: how to uninstall Devise?
I'm looking at solving the same problem today and since this is not answered, giving it a go =)
Models
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
In attr_accessible
, you may remove email
, :password
, password_confirmation
and remember_me
if you no longer need them.
Views
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).
Generally, all the views are stored in app/views/devise
.
Controllers
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.
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.
Migrations
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.
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
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
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.
BUT...
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.
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
.
Initializers and Locale
Remove devise.rb
in config/initializers
and devise.en.yml
in config/locales
.
Routes
Remove any devise_for
lines. These will raise errors after the removal of the gem.
Gem File
Yaay. All dome, remove the line gem 'devise'
from your gemfile.
How to delete a devise model from rails?
In your config/routes.rb
where there is any reference for device_for
, delete it. This should fix that error.
When you run devise generator it will generate some code into your config/routes.rb
file as you can see here:
https://github.com/plataformatec/devise/blob/master/lib/generators/devise/devise_generator.rb#L21
Removing a Devise user model possible?
I don't think devise offers a generator that would bring your model back to a previous version (similar to rails destroy migration ...
). Apart from removing the devise
method call from your model, you would need to get rid of the table itself (in a migration) and all the generated templates and controllers referring to the Student
model, just to keep things clean.
Howto Uninstall spree_auth_devise gem
Based on your information, try this:
Remove config/initializers/devise.rb
if you haven't done it
remove any devise
related code from your routes.rb
Might look similar to this:
devise_for :users, controllers: {
confirmations: 'users/confirmations',
passwords: 'users/passwords',
registrations: 'users/registrations',
sessions: 'users/sessions',
unlocks: 'users/unlocks'
}
Check if there are is any code related to devise
/spree_auth_devise
Might look like this in your User
model:
devise :database_authenticatable, :registerable
Or in your ApplicationController
or any other controller (git grep it):
before_action :authenticate_user!
Rollback your database changes (set STEP and RAILS_ENV appropirately):
rake db:rollback STEP=1 RAILS_ENV=development
If nothing helps, try a git revert or git reset
Regarding your error uninitialized constant Spree::AuthenticationHelpers
This module is defined in the spree_auth_gem
here and also gets included to your ApplicationController
in the engine.
If you did setup spree by this guide remove include Spree::AuthenticationHelpers
from your ApplicationController
.
Thes includes below might also be unnecessary. I would remove them 1 by 1 and see if your app still works:
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Order
include Spree::Core::ControllerHelpers::Store
helper 'spree/base'
How do I remove the Devise route to sign up?
I tried to do this as well, but a thread on the devise google group dissuaded me from searching for a really clean solution.
I'll quote José Valim (the Devise maintainer) :
There isn't a straight-forward option. You can either provide a patch
or use :skip => :registerable and add only the routes you want.
The original question was :
Is there any good way to remove a specific route (the delete route)
from Rails?
Remove Devise Flash Notices for Sign out
If you explicitly put in a blank string for this in your locale file, then Devise "won't bother" to render the message at all (e.g. there won't even be an empty HTML div).
#en.yml
devise:
sessions:
signed_in: 'Signed in successfully.'
signed_out: ''
How to Remove/Disable Sign Up From Devise
Solution to removing sign_up path from Devise
Enter the following at the beginning of routes.rb
Rails.application.routes.draw do
devise_scope :user do
get "/sign_in" => "devise/sessions#new" # custom path to login/sign_in
get "/sign_up" => "devise/registrations#new", as: "new_user_registration" # custom path to sign_up/registration
end
...After the statement above, add the following below in routes.rb
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
put 'users' => 'devise/registrations#update', :as => 'user_registration'
end
This will remove/disable the user/sign_up
path for Devise without breaking edit_user_registration_path
Restart your rails server and it should work.
Related Topics
How to Combine Overlapping Time Ranges (Time Ranges Union)
Dynamically Load Google Maps Markers with Gmaps4Rails
Ruby Datetime Parsing from 'Mm/Dd/Yyyy' Format
Unexpected Return (Localjumperror)
Ruby on Rails: How to Edit Database.Yml for Postgresql
Rails 4 Migration: How to Reorder Columns
Rails and Os X: How to Install Rmagick
Os X Mountain Lion: Gcc-4.2 No Such File or Directory
Forming Sanitary Shell Commands or System Calls in Ruby
Dividing Elements of a Ruby Array into an Exact Number of (Nearly) Equal-Sized Sub-Arrays
How to Unzip a File in Ruby on Rails
Including One Erb File into Another
Contact Form Mailer in Rails 4
I Have a Rails Task: Should I Use Script/Runner or Rake