railsでアプリケーションを作っているのでうすが、ログインすることができません。beybugでデータの中身を見たときは、
def
after_sign_in_path_for(resource)
case resource
when User
byebug
public_users_mypage_path
when Admin
admins_users_path
end
end
のコードが機能していませんでした。
どう解決すれば良いかアドバイスいただきたいです。
application.controller.rb
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? def after_sign_in_path_for(resource) case resource when User byebug public_users_mypage_path when Admin admins_users_path end end def after_sign_out_path_for(resource_or_scope) if resource_or_scope == :admin_admin_user new_admin_user_registaration_path else root_path end end protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :first_name_kana, :last_name_kana, :phone_number, :is_active ,:image,:instagram_id, :introduction]) end end
routes.rb
Rails.application.routes.draw do root :to => 'public/homes#top' devise_for :users, controllers: { sessions: 'user/sessions', registrations: 'user/registrations' } namespace :public, path: "" do get 'users/mypage' => 'users#mypage' get'posts_all' => 'posts#posts_all' post'posts_all' => 'posts#posts_all' get 'search_all' => 'users#search_all' post 'search_all' => 'users#search_all' resources :users, only: [:edit, :update ,:index , :show] do resources :posts, only: [:index,:create,:show,:edit,:update, :destroy] do delete 'post_item_destroy' post 'post_item_create' resources :post_items, only: [:destroy, :index] resources :likes, only: [:create, :destroy, :index] resources :comments, only: [:create, :destroy] end get 'unsubscribe/:id' => 'users#unsubscribe', as: 'confirm_unsubscribe' patch 'withdraw/:id' => 'users#withdraw', as: 'withdraw_user' put 'withdraw/:id' => 'users#withdraw' get 'users/tags' => 'posts#post_tags' resource :relationships, only: [:create, :destroy] get 'followings' => 'relationships#followings', as: 'followings' get 'followers' => 'relationships#followers', as: 'followers' resource :favorites, only: [:create, :destroy] end resources :messages, only: [:create] resources :rooms, only: [:create,:show, :index] end devise_for :admins, controllers: { sessions: 'user/sessions', registrations: 'user/registrations' } namespace :admins do resources :users resources :posts patch 'post_item_update' => 'posts#post_item_update' resources :tags, only: [:index] end end
回答よろしくお願いします
あなたの回答
tips
プレビュー