質問編集履歴

3

member.rbを追記

2018/03/30 05:29

投稿

tacro
tacro

スコア23

test CHANGED
File without changes
test CHANGED
@@ -265,3 +265,123 @@
265
265
 
266
266
 
267
267
  ```
268
+
269
+
270
+
271
+ ```Ruby
272
+
273
+ class Member
274
+
275
+ include Mongoid::Document
276
+
277
+ # Include default devise modules. Others available are:
278
+
279
+ # :confirmable, :lockable, :timeoutable and :omniauthable
280
+
281
+ attr_accessor :login
282
+
283
+ devise :database_authenticatable, :registerable,
284
+
285
+ :recoverable, :rememberable, :trackable, :validatable,
286
+
287
+ :confirmable, :authentication_keys => [:login]
288
+
289
+
290
+
291
+ validates :username,
292
+
293
+ uniqueness: { case_sensitive: :false },
294
+
295
+ length: { minimum: 4, maximum: 20 },
296
+
297
+ format: { with: /\A[a-z0-9]+\z/, message: "ユーザー名は半角英数字です"}
298
+
299
+
300
+
301
+
302
+
303
+ ## Database authenticatable
304
+
305
+ field :email, type: String, default: ""
306
+
307
+ field :encrypted_password, type: String, default: ""
308
+
309
+
310
+
311
+ ## Recoverable
312
+
313
+ field :reset_password_token, type: String
314
+
315
+ field :reset_password_sent_at, type: Time
316
+
317
+
318
+
319
+ ## Rememberable
320
+
321
+ field :remember_created_at, type: Time
322
+
323
+
324
+
325
+ ## Trackable
326
+
327
+ field :sign_in_count, type: Integer, default: 0
328
+
329
+ field :current_sign_in_at, type: Time
330
+
331
+ field :last_sign_in_at, type: Time
332
+
333
+ field :current_sign_in_ip, type: String
334
+
335
+ field :last_sign_in_ip, type: String
336
+
337
+
338
+
339
+ ## Confirmable
340
+
341
+ field :confirmation_token, type: String
342
+
343
+ field :confirmed_at, type: Time
344
+
345
+ field :confirmation_sent_at, type: Time
346
+
347
+ field :unconfirmed_email, type: String # Only if using reconfirmable
348
+
349
+
350
+
351
+ ## Lockable
352
+
353
+ # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
354
+
355
+ # field :unlock_token, type: String # Only if unlock strategy is :email or :both
356
+
357
+ # field :locked_at, type: Time
358
+
359
+
360
+
361
+ def self.find_first_by_auth_conditions(warden_conditions)
362
+
363
+ conditions = warden_conditions.dup
364
+
365
+ if login = conditions.delete(:login)
366
+
367
+ where(conditions).where(["username = :value OR lower(email) = lower(:value)", { :value => login }]).first
368
+
369
+ else
370
+
371
+ where(conditions).first
372
+
373
+ end
374
+
375
+ end
376
+
377
+
378
+
379
+ def will_save_change_to_email?
380
+
381
+ end
382
+
383
+
384
+
385
+ end
386
+
387
+ ```

2

routes.rbを追記しました!

2018/03/30 05:29

投稿

tacro
tacro

スコア23

test CHANGED
File without changes
test CHANGED
@@ -26,334 +26,242 @@
26
26
 
27
27
  細かなエラーメッセージは以下の通りです。
28
28
 
29
- ```text
30
-
31
- mongoid (6.4.0) lib/mongoid/validatable.rb:79:in `read_attribute_for_validation'
32
-
33
- activemodel (5.1.5) lib/active_model/validator.rb:148:in `block in validate'
34
-
35
- activemodel (5.1.5) lib/active_model/validator.rb:147:in `each'
36
-
37
- activemodel (5.1.5) lib/active_model/validator.rb:147:in `validate'
38
-
39
- activesupport (5.1.5) lib/active_support/callbacks.rb:413:in `block in make_lambda'
40
-
41
- activesupport (5.1.5) lib/active_support/callbacks.rb:197:in `block (2 levels) in halting'
42
-
43
- activesupport (5.1.5) lib/active_support/callbacks.rb:601:in `block (2 levels) in default_terminator'
44
-
45
- activesupport (5.1.5) lib/active_support/callbacks.rb:600:in `catch'
46
-
47
- activesupport (5.1.5) lib/active_support/callbacks.rb:600:in `block in default_terminator'
48
-
49
- activesupport (5.1.5) lib/active_support/callbacks.rb:198:in `block in halting'
50
-
51
- activesupport (5.1.5) lib/active_support/callbacks.rb:507:in `block in invoke_before'
52
-
53
- activesupport (5.1.5) lib/active_support/callbacks.rb:507:in `each'
54
-
55
- activesupport (5.1.5) lib/active_support/callbacks.rb:507:in `invoke_before'
56
-
57
- activesupport (5.1.5) lib/active_support/callbacks.rb:130:in `run_callbacks'
58
-
59
- mongoid (6.4.0) lib/mongoid/interceptable.rb:132:in `run_callbacks'
60
-
61
- activesupport (5.1.5) lib/active_support/callbacks.rb:827:in `_run_validate_callbacks'
62
-
63
- activemodel (5.1.5) lib/active_model/validations.rb:405:in `run_validations!'
64
-
65
- activemodel (5.1.5) lib/active_model/validations/callbacks.rb:114:in `block in run_validations!'
66
-
67
- activesupport (5.1.5) lib/active_support/callbacks.rb:131:in `run_callbacks'
68
-
69
- mongoid (6.4.0) lib/mongoid/interceptable.rb:132:in `run_callbacks'
70
-
71
- activesupport (5.1.5) lib/active_support/callbacks.rb:827:in `_run_validation_callbacks'
72
-
73
- activemodel (5.1.5) lib/active_model/validations/callbacks.rb:114:in `run_validations!'
74
-
75
- activemodel (5.1.5) lib/active_model/validations.rb:335:in `valid?'
76
-
77
- mongoid (6.4.0) lib/mongoid/validatable.rb:97:in `valid?'
78
-
79
- activemodel (5.1.5) lib/active_model/validations.rb:372:in `invalid?'
80
-
81
- mongoid (6.4.0) lib/mongoid/persistable/creatable.rb:117:in `prepare_insert'
82
-
83
- mongoid (6.4.0) lib/mongoid/persistable/creatable.rb:23:in `insert'
84
-
85
- mongoid (6.4.0) lib/mongoid/persistable/savable.rb:23:in `save'
86
-
87
- devise (4.4.3) app/controllers/devise/registrations_controller.rb:19:in `create'
88
-
89
- actionpack (5.1.5) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
90
-
91
- actionpack (5.1.5) lib/abstract_controller/base.rb:186:in `process_action'
92
-
93
- actionpack (5.1.5) lib/action_controller/metal/rendering.rb:30:in `process_action'
94
-
95
- actionpack (5.1.5) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
96
-
97
- activesupport (5.1.5) lib/active_support/callbacks.rb:131:in `run_callbacks'
98
-
99
- actionpack (5.1.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
100
-
101
- actionpack (5.1.5) lib/action_controller/metal/rescue.rb:20:in `process_action'
102
-
103
- actionpack (5.1.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
104
-
105
- activesupport (5.1.5) lib/active_support/notifications.rb:166:in `block in instrument'
106
-
107
- activesupport (5.1.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
108
-
109
- activesupport (5.1.5) lib/active_support/notifications.rb:166:in `instrument'
110
-
111
- actionpack (5.1.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
112
-
113
- actionpack (5.1.5) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
114
-
115
- activerecord (5.1.5) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
116
-
117
- actionpack (5.1.5) lib/abstract_controller/base.rb:124:in `process'
118
-
119
- actionview (5.1.5) lib/action_view/rendering.rb:30:in `process'
120
-
121
- actionpack (5.1.5) lib/action_controller/metal.rb:189:in `dispatch'
122
-
123
- actionpack (5.1.5) lib/action_controller/metal.rb:253:in `dispatch'
124
-
125
- actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
126
-
127
- actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:31:in `serve'
128
-
129
- actionpack (5.1.5) lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
130
-
131
- actionpack (5.1.5) lib/action_dispatch/routing/mapper.rb:46:in `serve'
132
-
133
- actionpack (5.1.5) lib/action_dispatch/journey/router.rb:50:in `block in serve'
134
-
135
- actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `each'
136
-
137
- actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `serve'
138
-
139
- actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:844:in `call'
140
-
141
- warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
142
-
143
- warden (1.2.7) lib/warden/manager.rb:35:in `catch'
144
-
145
- warden (1.2.7) lib/warden/manager.rb:35:in `call'
146
-
147
- rack (2.0.4) lib/rack/etag.rb:25:in `call'
148
-
149
- rack (2.0.4) lib/rack/conditional_get.rb:38:in `call'
150
-
151
- rack (2.0.4) lib/rack/head.rb:12:in `call'
152
-
153
- rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
154
-
155
- rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
156
-
157
- actionpack (5.1.5) lib/action_dispatch/middleware/cookies.rb:613:in `call'
158
-
159
- activerecord (5.1.5) lib/active_record/migration.rb:556:in `call'
160
-
161
- actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
162
-
163
- activesupport (5.1.5) lib/active_support/callbacks.rb:97:in `run_callbacks'
164
-
165
- actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
166
-
167
- actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
168
-
169
- actionpack (5.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
170
-
171
- web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
172
-
173
- web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
174
-
175
- web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
176
-
177
- web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
178
-
179
- actionpack (5.1.5) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
180
-
181
- railties (5.1.5) lib/rails/rack/logger.rb:36:in `call_app'
182
-
183
- railties (5.1.5) lib/rails/rack/logger.rb:24:in `block in call'
184
-
185
- activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `block in tagged'
186
-
187
- activesupport (5.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
188
-
189
- activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `tagged'
190
-
191
- railties (5.1.5) lib/rails/rack/logger.rb:24:in `call'
192
-
193
- sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
194
-
195
- actionpack (5.1.5) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
196
-
197
- actionpack (5.1.5) lib/action_dispatch/middleware/request_id.rb:25:in `call'
198
-
199
- rack (2.0.4) lib/rack/method_override.rb:22:in `call'
200
-
201
- rack (2.0.4) lib/rack/runtime.rb:22:in `call'
202
-
203
- activesupport (5.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
204
-
205
- actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
206
-
207
- actionpack (5.1.5) lib/action_dispatch/middleware/static.rb:125:in `call'
208
-
209
- rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
210
-
211
- railties (5.1.5) lib/rails/engine.rb:522:in `call'
212
-
213
- puma (3.11.2) lib/puma/configuration.rb:225:in `call'
214
-
215
- puma (3.11.2) lib/puma/server.rb:624:in `handle_request'
216
-
217
- puma (3.11.2) lib/puma/server.rb:438:in `process_client'
218
-
219
- puma (3.11.2) lib/puma/server.rb:302:in `block in run'
220
-
221
- puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
29
+ →【追記】本文の字数が足りないため、一旦省略します。
30
+
31
+
32
+
33
+ schema.rbやdbconsoleから、memberテーブルを確認してみましたが、usernameカラムはきちんと存在しています。
34
+
35
+
36
+
37
+ ```Ruby
38
+
39
+ ActiveRecord::Schema.define(version: 20180330025634) do
40
+
41
+ ...
42
+
43
+ create_table "members", force: :cascade do |t|
44
+
45
+ t.string "email", default: "", null: false
46
+
47
+ t.string "encrypted_password", default: "", null: false
48
+
49
+ t.string "reset_password_token"
50
+
51
+ t.datetime "reset_password_sent_at"
52
+
53
+ t.datetime "remember_created_at"
54
+
55
+ t.integer "sign_in_count", default: 0, null: false
56
+
57
+ t.datetime "current_sign_in_at"
58
+
59
+ t.datetime "last_sign_in_at"
60
+
61
+ t.string "current_sign_in_ip"
62
+
63
+ t.string "last_sign_in_ip"
64
+
65
+ t.string "confirmation_token"
66
+
67
+ t.datetime "confirmed_at"
68
+
69
+ t.datetime "confirmation_sent_at"
70
+
71
+ t.string "unconfirmed_email"
72
+
73
+ t.datetime "created_at", null: false
74
+
75
+ t.datetime "updated_at", null: false
76
+
77
+ t.string "username"
78
+
79
+ t.integer "user_group"
80
+
81
+ t.string "icon_image_name"
82
+
83
+ t.integer "gender"
84
+
85
+ t.string "profile"
86
+
87
+ t.index ["email"], name: "index_members_on_email", unique: true
88
+
89
+ t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true
90
+
91
+ t.index ["username"], name: "index_members_on_username", unique: true
92
+
93
+ end
94
+
95
+ ...
96
+
97
+ end
222
98
 
223
99
  ```
224
100
 
225
101
 
226
102
 
103
+ #該当のソースコード
104
+
227
- schema.rbやdbconsoleからmemberテブルを確認してみましたが、usernameカきちんと存在しています。
105
+ その他コントローラでのパラメータの設定以下の通りです。
228
-
229
-
230
106
 
231
107
  ```Ruby
232
108
 
109
+ class ApplicationController < ActionController::Base
110
+
111
+ protect_from_forgery with: :exception
112
+
113
+ before_action :authenticate_member!
114
+
115
+
116
+
117
+ before_action :configure_permitted_parameters, if: :devise_controller?
118
+
119
+
120
+
121
+ protected
122
+
123
+
124
+
125
+ def configure_permitted_parameters
126
+
233
- ActiveRecord::Schema.define(version: 20180330025634) do
127
+ devise_parameter_sanitizer.permit(:sign_up) do |member_params|
128
+
129
+ member_params.permit(:username, :email, :password, :password_confirmation, :gender, :user_group, :remember_me)
130
+
131
+ end
132
+
133
+ devise_parameter_sanitizer.permit(:sign_in) do |member_params|
134
+
135
+ member_params.permit(:login, :username, :email, :password, :remember_me)
136
+
137
+ end
138
+
139
+ devise_parameter_sanitizer.permit(:account_update) do |member_params|
140
+
141
+ member_params.permit(:username, :email, :password, :password_confirmation, :current_password)
142
+
143
+ end
144
+
145
+ end
234
146
 
235
147
  ...
236
148
 
237
- create_table "members", force: :cascade do |t|
238
-
239
- t.string "email", default: "", null: false
240
-
241
- t.string "encrypted_password", default: "", null: false
242
-
243
- t.string "reset_password_token"
244
-
245
- t.datetime "reset_password_sent_at"
246
-
247
- t.datetime "remember_created_at"
248
-
249
- t.integer "sign_in_count", default: 0, null: false
250
-
251
- t.datetime "current_sign_in_at"
252
-
253
- t.datetime "last_sign_in_at"
254
-
255
- t.string "current_sign_in_ip"
256
-
257
- t.string "last_sign_in_ip"
258
-
259
- t.string "confirmation_token"
260
-
261
- t.datetime "confirmed_at"
262
-
263
- t.datetime "confirmation_sent_at"
264
-
265
- t.string "unconfirmed_email"
266
-
267
- t.datetime "created_at", null: false
268
-
269
- t.datetime "updated_at", null: false
270
-
271
- t.string "username"
272
-
273
- t.integer "user_group"
274
-
275
- t.string "icon_image_name"
276
-
277
- t.integer "gender"
278
-
279
- t.string "profile"
280
-
281
- t.index ["email"], name: "index_members_on_email", unique: true
282
-
283
- t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true
284
-
285
- t.index ["username"], name: "index_members_on_username", unique: true
149
+ end
150
+
151
+ ```
152
+
153
+
154
+
155
+ #試してみたこと
156
+
157
+ rake db:migrate:resetでデータベースのリセットを行ったりしてみましたが、解決しませんでした。
158
+
159
+
160
+
161
+ #使用している環境
162
+
163
+ Ruby on Rails 5
164
+
165
+ devise (4.4.3)
166
+
167
+
168
+
169
+ #追記
170
+
171
+ ```Ruby
172
+
173
+ Rails.application.routes.draw do
174
+
175
+ devise_for :members
176
+
177
+ root "home#top"
178
+
179
+
180
+
181
+ # get 'signup' => "users#new"
182
+
183
+ # get 'login' => "users#login_form"
184
+
185
+ # post 'login' => "users#login"
186
+
187
+ # post 'logout' => "users#logout"
188
+
189
+ # get 'users/:id/signup_designer' => "users#new_designer"
190
+
191
+ # patch 'users/:id/register_designer' => "users#register_designer"
192
+
193
+ #
194
+
195
+ # post 'users/create' => "users#create"
196
+
197
+ # get 'users/:id' => "users#show"
198
+
199
+ # get 'users/:id/edit' => "users#edit"
200
+
201
+ # patch 'users/:id/update' => "users#update"
202
+
203
+ # patch "users/:id/update_designer" => "users#update_designer"
204
+
205
+ # get 'users/:id/likes' => "users#likes"
206
+
207
+ # get 'users/:id/timeline' => "users#following_posts"
208
+
209
+
210
+
211
+ get 'posts/index'=> "posts#index"
212
+
213
+ get 'posts/new' => "posts#new"
214
+
215
+ post 'posts/create' => "posts#create"
216
+
217
+ post "posts/:id/comment" => "posts#comment"
218
+
219
+
220
+
221
+ post "comments/:id/destroy" => "comments#destroy"
222
+
223
+
224
+
225
+ get 'posts/:id' => "posts#show"
226
+
227
+ get 'posts/:id/edit' => "posts#edit"
228
+
229
+ patch 'posts/:id/update' => "posts#update"
230
+
231
+ post 'posts/:id/destroy' => "posts#destroy"
232
+
233
+
234
+
235
+ post '/likes/:post_id/create' => "likes#create"
236
+
237
+ post '/likes/:post_id/destroy' => "likes#destroy"
238
+
239
+
240
+
241
+ get '/' => "home#top"
242
+
243
+ get "about" => "home#about"
244
+
245
+
246
+
247
+ resources :users do
248
+
249
+ member do
250
+
251
+ get :following, :followers
252
+
253
+ end
286
254
 
287
255
  end
288
256
 
289
- ...
257
+ resources :relationships, only: [:create, :destroy]
258
+
259
+
260
+
261
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
290
262
 
291
263
  end
292
264
 
265
+
266
+
293
267
  ```
294
-
295
-
296
-
297
- #該当のソースコード
298
-
299
- その他、コントローラでのパラメータの設定は以下の通りです。
300
-
301
- ```Ruby
302
-
303
- class ApplicationController < ActionController::Base
304
-
305
- protect_from_forgery with: :exception
306
-
307
- before_action :authenticate_member!
308
-
309
-
310
-
311
- before_action :configure_permitted_parameters, if: :devise_controller?
312
-
313
-
314
-
315
- protected
316
-
317
-
318
-
319
- def configure_permitted_parameters
320
-
321
- devise_parameter_sanitizer.permit(:sign_up) do |member_params|
322
-
323
- member_params.permit(:username, :email, :password, :password_confirmation, :gender, :user_group, :remember_me)
324
-
325
- end
326
-
327
- devise_parameter_sanitizer.permit(:sign_in) do |member_params|
328
-
329
- member_params.permit(:login, :username, :email, :password, :remember_me)
330
-
331
- end
332
-
333
- devise_parameter_sanitizer.permit(:account_update) do |member_params|
334
-
335
- member_params.permit(:username, :email, :password, :password_confirmation, :current_password)
336
-
337
- end
338
-
339
- end
340
-
341
- ...
342
-
343
- end
344
-
345
- ```
346
-
347
-
348
-
349
- #試してみたこと
350
-
351
- rake db:migrate:resetでデータベースのリセットを行ったりしてみましたが、解決しませんでした。
352
-
353
-
354
-
355
- #使用している環境
356
-
357
- Ruby on Rails 5
358
-
359
- devise (4.4.3)

1

エラーメッセージの記法を引用からコードに変更

2018/03/30 04:38

投稿

tacro
tacro

スコア23

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,9 @@
26
26
 
27
27
  細かなエラーメッセージは以下の通りです。
28
28
 
29
+ ```text
30
+
29
- > mongoid (6.4.0) lib/mongoid/validatable.rb:79:in `read_attribute_for_validation'
31
+ mongoid (6.4.0) lib/mongoid/validatable.rb:79:in `read_attribute_for_validation'
30
32
 
31
33
  activemodel (5.1.5) lib/active_model/validator.rb:148:in `block in validate'
32
34
 
@@ -218,6 +220,8 @@
218
220
 
219
221
  puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
220
222
 
223
+ ```
224
+
221
225
 
222
226
 
223
227
  schema.rbやdbconsoleから、memberテーブルを確認してみましたが、usernameカラムはきちんと存在しています。