[Ruby on Rails] How to avoid creating unnecessary routes for devise

Target

Do not create unnecessary routes that devise automatically creates. → Prevent the creation of a new admin.

Development environment

ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina

Premise

-Build login environment with devise

Described in seed

Describe the administrator information in seed.

db/seeds.rb


...

Admin.create!(
  email: '[email protected]',
  password: 'aaaaaa',
)

Terminal


$ rails db:seed

You can now log in to the admin page.

Edit routes

config/routes.rb


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

If the login page is in the default state

If nothing is done, an error will occur, so delete the relevant part of the following file.

erb:app/views/admins/shared/_links.html.erb


<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
  <%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end %>

<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
  <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end %>

reference

How do I remove the Devise route to sign up?

Recommended Posts

[Ruby on Rails] How to avoid creating unnecessary routes for devise
How to use Ruby on Rails
[Ruby on Rails] How to use CarrierWave
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
[Ruby on Rails] How to display error messages
How to add / remove Ruby on Rails columns
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] How to use session method
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Ruby on Rails DB Tips for creating methods to reduce the load
Rails / Ruby: How to get HTML text for Mail
[Rails] How to install devise
[Ruby on Rails] How to change the column name
How to read rails routes
[Ruby On Rails] How to reset DB in Heroku
Explanation of Ruby on rails for beginners ② ~ Creating links ~
(Ruby on Rails6) How to create models and tables
[Ruby on Rails] How to implement tagging / incremental search function for posts (without gem)
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
How to display a graph in Ruby on Rails (LazyHighChart)
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
[Rails] How to use devise (Note)
How to deploy Bootstrap on Rails
Rails on Tiles (how to write)
Ruby On Rails devise routing conflict
[RSpec on Rails] How to write test code for beginners by beginners
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
[Ruby on Rails] Use the resources method to automatically create routes.
[Ruby on Rails] About bundler (for beginners)
Deploy to Heroku [Ruby on Rails] Beginner
[Ruby] How to use slice for beginners
Preparing to introduce jQuery to Ruby on Rails
Explanation of Ruby on rails for beginners ①
[Ruby on Rails] Button to return to top
[Rails] How to translate devise into Japanese
How to create a query using variables in GraphQL [Using Ruby on Rails]
How to implement gem "summer note" in wysiwyg editor in Ruby on Rails
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to solve the local environment construction of Ruby on Rails (MAC)!
How to debug the processing in the Ruby on Rails model only on the console
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[Ruby On Rails] How to search the contents of params using include?
[Ruby on Rails] How to log in with only your name and password using the gem devise
[Ruby on Rails] When logging in for the first time ・ How to split the screen in half using jQuery
[Rails] How to decide the destination by "rails routes"
Validation settings for Ruby on Rails login function
[Ruby on Rails] Select2 introduction memo for Webpacker
[Rails] How to implement unit tests for models
[Rails MySQL] How to reset DB on heroku
[Rails] Procedure for linking databases with Ruby On Rails
[Rails] How to use Gem'rails-i18n' for Japanese support
How to implement Pagination in GraphQL (for ruby)
[Ruby on Rails] How to make the link destination part of the specified id
How to resolve errors that occur in the "Ruby on Rails" integration test
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
How to implement image posting function using Active Storage in Ruby on Rails
How to install Ruby on an EC2 instance on AWS
[Introduction] Try to create a Ruby on Rails application