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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Q&A

解決済

1回答

752閲覧

deviseの新規登録ができない

Maaxuhbd

総合スコア7

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

0グッド

0クリップ

投稿2021/09/20 13:13

deivseで新規登録とログインを行えるようにしたい。

現在、ユーザーの作成には成功しているようだが、before_action :authenticate_end_user!を記載しているコントローラーへの遷移も行えない状態です。

Model名:EndUser

rails cを使用しEndUserの中身えを確認すると問題なく作成されています。

#<EndUser id: 10, email: "xxx@sxx", first_name: "xxx", last_name: "xxx", first_name_kana: "xxxx", last_name_kana: "xxx", address: "xxxx", phone_number: "xxxx", post_code: "xxx", is_deleted: nil, created_at: "2021-09-20 11:38:51", updated_at: "2021-09-20 11:38:51">, ...]>

application.controller.rb

ruby

1class ApplicationController < ActionController::Base 2 before_action :configure_permitted_parameters, if: :devise_controller? 3 4 protected 5 6 def after_sign_in_path_for(resource) 7 case resource 8 when Public 9 customers_mypage_path 10 when Admin 11 admins_path 12 end 13 end 14 15 #ログイン時のパラメータ 16 def configure_permitted_parameters 17 devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :first_name_kana, :last_name_kana, :address, :phone_number, :post_code,:is_deleted]) 18 end 19end

customerscontroller

ruby

1class Public::CustomersController < ApplicationController 2 before_action :authenticate_end_user! 3 4 #マイページ 5 def show 6 @user = current_end_user 7 end 8 9 #登録情報編集画面 10 def edit 11 @user = current_end_user 12 end 13 14 #登録情報更新 15 def update 16 @user = current_end_user 17 @user.update 18 redirect_to customers_mypage_path 19 end 20 21 #退会確認画面 22 def confirm 23 @user = current_end_user 24 end 25 26 #退会ステータスの更新 27 def withdraw 28 # @user = EndUser.find_by(params[:email]) 29 @user = current_end_user 30 #is_deletedカラムをtrueに変更 31 @user.update(is_deleted: true) 32 #deviseのログアウトとの違い 33 # reset_session 34 # redirect_to root_path 35 end 36 37 private 38 39 def end_users_params 40 params.require(:end_users).permit(:first_name,:first_name,:last_name,:first_name_kana,:last_name_kana,:address,:phone_number,:post_code) 41 end 42end

ターミナル

ruby

1 (0.1ms) begin transaction 2 ↳ vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.6/lib/active_record/log_subscriber.rb:98 3 EndUser Exists (1.2ms) SELECT 1 AS one FROM "end_users" WHERE "end_users"."email" = ? LIMIT ? [["email", "cc@cc"], ["LIMIT", 1]] 4 ↳ vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.6/lib/active_record/log_subscriber.rb:98 5 EndUser Create (3.8ms) INSERT INTO "end_users" ("email", "encrypted_password", "first_name", "last_name", "first_name_kana", "last_name_kana", "address", "phone_number", "post_code", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["email", "cc@cc"], ["encrypted_password", "$2a$12$z3KNsPf24W/7SI7RtfgNaue6Hk44kCbOgw9xBRSXUSJ..5cSFf59K"], ["first_name", "www"], ["last_name", "wwwzc"], ["first_name_kana", "ccc"], ["last_name_kana", "ccc"], ["address", "vvv"], ["phone_number", "vvvv"], ["post_code", "vvvvv"], ["created_at", "2021-09-20 12:55:35.234815"], ["updated_at", "2021-09-20 12:55:35.234815"]] 6 ↳ vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.6/lib/active_record/log_subscriber.rb:98 7 (1.4ms) commit transaction 8 ↳ vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.6/lib/active_record/log_subscriber.rb:98 9Redirected to http://localhost:3000/ 10Completed 302 Found in 430ms (ActiveRecord: 6.5ms)

schema.rb

ruby

1---省略--- 2 3create_table "end_users", force: :cascade do |t| 4 t.string "email", default: "", null: false 5 t.string "encrypted_password", default: "", null: false 6 t.string "reset_password_token" 7 t.datetime "reset_password_sent_at" 8 t.datetime "remember_created_at" 9 t.string "first_name" 10 t.string "last_name" 11 t.string "first_name_kana" 12 t.string "last_name_kana" 13 t.string "address" 14 t.string "phone_number" 15 t.string "post_code" 16 t.boolean "is_deleted", default: false, null: false 17 t.datetime "created_at", null: false 18 t.datetime "updated_at", null: false 19 t.index ["email"], name: "index_end_users_on_email", unique: true 20 t.index ["reset_password_token"], name: "index_end_users_on_reset_password_token", unique: true 21 end

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

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

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

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

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

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

guest

回答1

0

自己解決

no fileというマイグレーションファイルがupになっていたため、エラーになっていました。

投稿2021/09/20 15:03

Maaxuhbd

総合スコア7

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問