deviseにてユーザーのログイン後にリダイレクト先を指定したいのですが
Couldn't find Customer without an ID
というエラーが出ていて色々調べて試したりしたのですが解決方法がわかりません
get 'customers' => 'customers#show'に飛ばしたいです
Rails.application.routes.draw do devise_for :admins, controllers: { sessions: 'admins/sessions', passwords: 'admins/passwords', registrations: 'admins/registrations' } devise_for :customers, controllers: { sessions: 'customers/sessions', passwords: 'customers/passwords', registrations: 'customers/registrations' } # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root to: 'public/homes#top' scope module: :public do get "about" => "homes#about" resources :items,only: [:index, :show] get 'customers' => 'customers#show' get 'customers/edit' => 'customers#edit' patch 'customers' => 'customers#update' post 'customers' => 'customers#create' patch 'customers/:id' => 'customers#withdraw' end namespace :admin do resources :items resources :genres,only: [:index, :create, :edit, :update] resources :customers,only: [:index,:show,:edit,:update] end end
# frozen_string_literal: true class Customers::RegistrationsController < Devise::RegistrationsController # before_action :configure_sign_up_params, only: [:create] # before_action :configure_account_update_params, only: [:update] # GET /resource/sign_up # def new # super # end # POST /resource # def create # super # end # GET /resource/edit # def edit # super # end # PUT /resource # def update # super # end # DELETE /resource # def destroy # super # end # GET /resource/cancel # Forces the session data which is usually expired after sign # in to be expired now. This is useful if the user wants to # cancel oauth signing in/up in the middle of the process, # removing all OAuth session data. # def cancel # super # end # protected # If you have extra params to permit, append them to the sanitizer. # def configure_sign_up_params # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) # end # If you have extra params to permit, append them to the sanitizer. # def configure_account_update_params # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) # end #The path used after sign up. def after_sign_up_path_for(resource) customers_path(resource) end # The path used after sign up for inactive accounts. # def after_inactive_sign_up_path_for(resource) # customers_path(resource) #end end
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) end def after_sign_in_path_for(resource) customers_path(resource) end end class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) end def after_sign_in_path_for(resource) customers_path(resource) end end
class Public::CustomersController < ApplicationController def show @customer = Customer.find(params[:id]) end def edit @customer = Customer.find(params[:id]) end def update end def create end def withdraw end private def customer_params params.require(:customer).permit(:first_name,:last_name,:first_name_kana,:last_name_kana,:postal_code,:telephone_number, :is_active, :address) end end
このような感じです
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/23 23:38
2022/05/24 00:34
2022/05/24 00:48