質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

598閲覧

railsにてエラーの解決方法がわかりません

uri88

総合スコア0

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2022/05/23 14:35

編集2022/05/24 09:48

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

このような感じです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

get 'customers' => 'customers#show'に飛ばしたいです

Couldn't find Customer without an IDというメッセージのとおりです。public/customers#showを行うにはIDが必要ですが、単にルーティングを引いただけではそのIDは供給されません。

投稿2022/05/23 23:30

maisumakun

総合スコア145121

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2022/05/23 23:38

どのcustomerを表示したいのですか?
uri88

2022/05/24 00:34

ログイン後に詳細画面に飛ばしたいです
maisumakun

2022/05/24 00:48

「どのcustomerの」詳細画面ですか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問