teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

書式の改善

2020/10/01 05:49

投稿

waiwa
waiwa

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- devise(複数モデル)のログインを実装した
1
+ deviseで登録情報がsaveできな
body CHANGED
@@ -2,37 +2,57 @@
2
2
 
3
3
  現在、rubyを使って、プラットフォームアプリを作成しています。
4
4
  deviseを導入して、複数モデルを作成し、ログインを実行したところ
5
- 下記のエラー発生しました。通常通りログインができるようにしたいです。
5
+ 保存されていせんでした。通常通りログインができるようにしたいです。
6
6
  初学者ゆえ、もろもろ抜けているところなどありましたら、ご指摘いただければと思います。
7
7
 
8
8
  ### 発生している問題・エラーメッセージ
9
9
 
10
10
  ```
11
- #ターミナル
12
- Processing by Speakers::SessionsController#new as HTML
13
- Parameters: {"authenticity_token"=>"Dm+v9z2g010PtNnxDLrqbVEbs0aTl88X2pxdJCxp3aaZsR6/Zv9F/gDL9yXq8dULlZcSgqKRB7wP/wrn9/PLXQ==", "speaker"=>{"nickname"=>"wawa", "email"=>"wa@wa", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "first_name"=>"あ", "last_name"=>"あ", "first_name_kana"=>"ア", "last_name_kana"=>"ア", "birth_date(1i)"=>"1934", "birth_date(2i)"=>"3", "birth_date(3i)"=>"5"}, "commit"=>"会員登録"}
14
- Unpermitted parameters: :nickname, :password_confirmation, :first_name, :last_name, :first_name_kana, :last_name_kana, :birth_date(1i), :birth_date(2i), :birth_date(3i)
15
- Rendering speakers/sessions/new.html.erb within layouts/application
16
- Rendered layouts/shared/_second-header.html.erb (Duration: 6.5ms | Allocations: 698)
17
- Rendered speakers/sessions/new.html.erb within layouts/application (Duration: 8.9ms | Allocations: 1144)
18
- [Webpacker] Everything's up-to-date. Nothing to do
19
- Completed 200 OK in 373ms (Views: 100.3ms | ActiveRecord: 0.0ms | Allocations: 22312)
11
+ ターミナル
12
+
13
+ Started POST "/speakers" for ::1 at 2020-10-01 14:33:00 +0900
14
+ Processing by Speakers::RegistrationsController#create as HTML
15
+ Parameters: {"authenticity_token"=>"cMpj1qCQPUrcY8s44bXNgiKuqAIsaUdlQThsr0H4h63nFNKe+8+r6dMc5ewH/vLk5iIJxh1vj86UWztsmmKRVg==", "speaker"=>{"nickname"=>"wa", "email"=>"wa@wa", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "first_name"=>"あ", "last_name"=>"あ", "first_name_kana"=>"ア", "last_name_kana"=>"ア", "birth_date(1i)"=>"1931", "birth_date(2i)"=>"6", "birth_date(3i)"=>"5"}, "commit"=>"会員登録"}
16
+
17
+ From: /Users/yuuri/projects/wacca/app/controllers/speakers/registrations_controller.rb:15 Speakers::RegistrationsController#create:
18
+
19
+ 13: def create
20
+ 14: @speaker = Speaker.new(speaker_signup_params)
21
+ => 15: binding.pry
22
+ 16: if @speaker.save
23
+ 17: redirect_to root_path
24
+ 18: else
25
+ 19: render :new
26
+ 20: end
27
+ 21: end
28
+
29
+ [1] pry(#<Speakers::RegistrationsController>)> @speaker
30
+ => #<Speaker id: nil, first_name: nil, last_name: nil, first_name_kana: nil, last_name_kana: nil, nickname: "", email: "", birth_date: nil, created_at: nil, updated_at: nil>
31
+ [2] pry(#<Speakers::RegistrationsController>)>
20
32
  ```
21
33
 
22
34
  ```
23
- #コントローラー
35
+ コントローラー
24
36
 
37
+ # frozen_string_literal: true
38
+
25
39
  class Speakers::RegistrationsController < Devise::RegistrationsController
26
- before_action :configure_sign_up_params, only: [:create]
40
+ before_action :speaker_signup_params, only: [:create]
27
41
  # before_action :configure_account_update_params, only: [:update]
28
42
 
29
43
  # GET /resource/sign_up
30
- # def new
44
+ def new
31
- # super
45
+ @speaker = Speaker.new
32
- # end
46
+ end
33
47
 
34
- # POST /resource
48
+ # POST /resource
35
49
  def create
50
+ @speaker = Speaker.new(speaker_signup_params)
51
+ if @speaker.save
52
+ redirect_to root_path
53
+ else
54
+ render :new
55
+ end
36
56
  end
37
57
 
38
58
  # GET /resource/edit
@@ -59,11 +79,11 @@
59
79
  # super
60
80
  # end
61
81
 
62
- # protected
82
+ protected
63
83
 
64
84
  # If you have extra params to permit, append them to the sanitizer.
65
- def configure_sign_up_params
85
+ def speaker_signup_params
66
- devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname,:email,:encrypted_password,:first_name,:last_name,:first_name_kana,:last_name_kana,:birth_date])
86
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name,:last_name,:first_name_kana,:last_name_kana,:email,:nickname,:birth_date])
67
87
  end
68
88
 
69
89
  # If you have extra params to permit, append them to the sanitizer.
@@ -81,10 +101,5 @@
81
101
  # super(resource)
82
102
  # end
83
103
  end
84
- ```
85
104
 
86
- ### 試したこと
105
+ ```
87
-
88
- 下記のサイトを参考にコントローラーの作成を行いました。
89
- https://qiita.com/kinpin/items/21b1badcfe19aca84038
90
- https://qiita.com/Yama-to/items/54ab4ce08e126ef7dade

1

タイトルの編集

2020/10/01 05:49

投稿

waiwa
waiwa

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- devise(複数モデル)のログイン
1
+ devise(複数モデル)のログインを実装したい
body CHANGED
File without changes