How to remove / disconnect a subscription

I am trying to remove / disable the path "user / sign_up" from Devise. I do this because I do not want random people to access the application. I have partially working by adding the following to 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 ... devise_for :users, :skip => :registration end 

However, this violates <%= link_to "Profile", edit_user_registration_path, class: "btn btn-info btn-flat" %>

which I want to save so that users can update their profile. I know this because of devise_for :users, :skip => :registration

Is there a solution for this problem?

Launch

Develop (4.2.0, 4.1.1, 4.1.0)

Rails 4.2.5

ruby 2.3.0p0 (version 2015-12-25 version 53290) [x86_64-linux]

+7
ruby-on-rails devise
source share
4 answers

The easiest way is to simply remove the ": registerable" devise module from the default list defined in your model (the class name used for application users, usually User ).

 class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable ... end 

So you get the following:

 class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable ... end 
+15
source share

Solution to remove sign_up path from Devise

Type routes.rb at the beginning

following:
 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 above add the following to routes.rb below

 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 for development without violating edit_user_registration_path

Reboot the rails server and it should work.

+8
source share

Since how is just a devise_scope alias, you can put everything in one block.

 devise_for :users, skip: [:registrations] as :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 get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration' put 'users' => 'devise/registrations#update', :as => 'user_registration' end 
+2
source share

I had the same problem. My solution is a combination of these answers:

First Comment / Delete :registerable on user.rb

class User < ActiveRecord::Base devise :database_authenticatable, #:registerable, :recoverable, :rememberable, :trackable, :validatable end Second removal of registration paths from development in routes.rb

devise_for :users, :skip => [:registrations] , controllers: { sessions: 'users/sessions' }

Now the developer will skip all the registration links from his submission, and also you no longer have registration ways on your routes.

0
source share

All Articles