質問編集履歴

2

書式の改善

2020/10/01 05:49

投稿

waiwa
waiwa

スコア0

test CHANGED
@@ -1 +1 @@
1
- devise(複数モデル)のログインを実装した
1
+ deviseで登録情報がsaveできな
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  deviseを導入して、複数モデルを作成し、ログインを実行したところ
8
8
 
9
- 下記のエラー発生しました。通常通りログインができるようにしたいです。
9
+ 保存されていせんでした。通常通りログインができるようにしたいです。
10
10
 
11
11
  初学者ゆえ、もろもろ抜けているところなどありましたら、ご指摘いただければと思います。
12
12
 
@@ -18,37 +18,65 @@
18
18
 
19
19
  ```
20
20
 
21
- #ターミナル
22
-
23
- Processing by Speakers::SessionsController#new as HTML
24
-
25
- 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"=>"会員登録"}
26
-
27
- Unpermitted parameters: :nickname, :password_confirmation, :first_name, :last_name, :first_name_kana, :last_name_kana, :birth_date(1i), :birth_date(2i), :birth_date(3i)
28
-
29
- Rendering speakers/sessions/new.html.erb within layouts/application
30
-
31
- Rendered layouts/shared/_second-header.html.erb (Duration: 6.5ms | Allocations: 698)
32
-
33
- Rendered speakers/sessions/new.html.erb within layouts/application (Duration: 8.9ms | Allocations: 1144)
34
-
35
- [Webpacker] Everything's up-to-date. Nothing to do
36
-
37
- Completed 200 OK in 373ms (Views: 100.3ms | ActiveRecord: 0.0ms | Allocations: 22312)
38
-
39
- ```
40
-
41
-
42
-
43
- ```
44
-
45
- #コントローラー
21
+ ターミナル
22
+
23
+
24
+
25
+ Started POST "/speakers" for ::1 at 2020-10-01 14:33:00 +0900
26
+
27
+ Processing by Speakers::RegistrationsController#create as HTML
28
+
29
+ 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"=>"会員登録"}
30
+
31
+
32
+
33
+ From: /Users/yuuri/projects/wacca/app/controllers/speakers/registrations_controller.rb:15 Speakers::RegistrationsController#create:
34
+
35
+
36
+
37
+ 13: def create
38
+
39
+ 14: @speaker = Speaker.new(speaker_signup_params)
40
+
41
+ => 15: binding.pry
42
+
43
+ 16: if @speaker.save
44
+
45
+ 17: redirect_to root_path
46
+
47
+ 18: else
48
+
49
+ 19: render :new
50
+
51
+ 20: end
52
+
53
+ 21: end
54
+
55
+
56
+
57
+ [1] pry(#<Speakers::RegistrationsController>)> @speaker
58
+
59
+ => #<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>
60
+
61
+ [2] pry(#<Speakers::RegistrationsController>)>
62
+
63
+ ```
64
+
65
+
66
+
67
+ ```
68
+
69
+ コントローラー
70
+
71
+
72
+
73
+ # frozen_string_literal: true
46
74
 
47
75
 
48
76
 
49
77
  class Speakers::RegistrationsController < Devise::RegistrationsController
50
78
 
51
- before_action :configure_sign_up_params, only: [:create]
79
+ before_action :speaker_signup_params, only: [:create]
52
80
 
53
81
  # before_action :configure_account_update_params, only: [:update]
54
82
 
@@ -56,18 +84,30 @@
56
84
 
57
85
  # GET /resource/sign_up
58
86
 
59
- # def new
87
+ def new
60
-
88
+
61
- # super
89
+ @speaker = Speaker.new
62
-
90
+
63
- # end
91
+ end
64
-
65
-
66
-
92
+
93
+
94
+
67
- # POST /resource
95
+ # POST /resource
68
96
 
69
97
  def create
70
98
 
99
+ @speaker = Speaker.new(speaker_signup_params)
100
+
101
+ if @speaker.save
102
+
103
+ redirect_to root_path
104
+
105
+ else
106
+
107
+ render :new
108
+
109
+ end
110
+
71
111
  end
72
112
 
73
113
 
@@ -120,15 +160,15 @@
120
160
 
121
161
 
122
162
 
123
- # protected
163
+ protected
124
164
 
125
165
 
126
166
 
127
167
  # If you have extra params to permit, append them to the sanitizer.
128
168
 
129
- def configure_sign_up_params
169
+ def speaker_signup_params
130
-
170
+
131
- devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname,:email,:encrypted_password,:first_name,:last_name,:first_name_kana,:last_name_kana,:birth_date])
171
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name,:last_name,:first_name_kana,:last_name_kana,:email,:nickname,:birth_date])
132
172
 
133
173
  end
134
174
 
@@ -164,16 +204,6 @@
164
204
 
165
205
  end
166
206
 
207
+
208
+
167
- ```
209
+ ```
168
-
169
-
170
-
171
- ### 試したこと
172
-
173
-
174
-
175
- 下記のサイトを参考にコントローラーの作成を行いました。
176
-
177
- https://qiita.com/kinpin/items/21b1badcfe19aca84038
178
-
179
- https://qiita.com/Yama-to/items/54ab4ce08e126ef7dade

1

タイトルの編集

2020/10/01 05:49

投稿

waiwa
waiwa

スコア0

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