LoginSignup
rrr013
@rrr013 (お腹 空いた)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Rails サインアウト機能でエラーが出るので解決したい(devise)

解決したいこと

Ruby on RailsでECサイトをつくっています。
管理者(admin)と顧客(customer)に(devise)でログイン認証を分けております。

adminでサインアウトするとエラーになってしまいます。

発生している問題・エラー

Routing Error

No route matches [GET] "/admins/sign_out"

該当するソースコード

routes.rbのコードです。

 Rails.application.routes.draw do

  devise_for :admins, controllers: {
    sessions: 'admin/sessions'
  }
  
  devise_for :customers, controllers: {
    sessions: 'customer/sessions',
    registrations: 'customer/registrations'
  }

  root to: 'pages#home'

  namespace :admin do
    resources :products, only: %i[index show new create edit update]
  end
  
end

ApplicationControllerのコードです。

class ApplicationController < ActionController::Base
  before_action :authenticate_admin!, except: [:home]
  
  
  def after_sign_out_path_for(resource)
    flash[:notice] = "Signed out successfully."
     root_path
  end

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:email])
  end
end

サインアウトに使用するリンクとパスです。

<li class="nav-item">
  <%= link_to destroy_admin_session_path, method: :delete, class: "nav-link text-light" do %>
    サインアウト
  <% end %>
</li>

自分で試したこと

・rails routesでパスの確認
・routes.rbのコードの確認

・config/initializers/devise.rbの確認

# Set this configuration to false if you want /users/sign_out to sign out
  # only the current scope. By default, Devise signs out all scopes.

  config.sign_out_all_scopes = false

  # ==> Navigation configuration
  # Lists the formats that should be treated as navigational. Formats like
  # :html should redirect to the sign in page when the user does not have
  # access, but formats like :xml or :json, should return 401.
  #
  # If you have any extra navigational formats, like :iphone or :mobile, you
  # should add them to the navigational formats lists.
  #
  # The "*/*" below is required to match Internet Explorer requests.
  # config.navigational_formats = ['*/*', :html, :turbo_stream]

  # The default HTTP method used to sign out a resource. Default is :delete.

  config.sign_out_via = :delete

よろしくお願いいたします。

0

No Answers yet.

Your answer might help someone💌