Do not create unnecessary routes that devise automatically creates. → Prevent the creation of a new admin.
ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina
-Build login environment with devise
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.
config/routes.rb
devise_for :admins, :skip => [:registrations, :password],controllers: {
sessions: 'admins/sessions',
}
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 %>
How do I remove the Devise route to sign up?
Recommended Posts