前提・実現したいこと
こんにちは。
前に確認したときはユーザー編集機能は問題なくできていたのですが、改めてユーザー編集を試したら更新できなくなっていました。
- deviseを用いてユーザー登録機能は実装済みでDBにも登録できている
- ユーザー情報を更新しようとすると、エラーは出ないがDBには登録されない
ターミナル
Finished "/cable/" [WebSocket] for 172.20.0.1 at 2021-04-09 00:30:25 +0000 MessageChannel stopped streaming from message_channel Started GET "/cable" for 172.20.0.1 at 2021-04-09 00:30:25 +0000 Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1 Started GET "/cable/" [WebSocket] for 172.20.0.1 at 2021-04-09 00:30:25 +0000 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) MessageChannel is transmitting the subscription confirmation MessageChannel is streaming from message_channel Started PATCH "/users/3" for 172.20.0.1 at 2021-04-09 00:30:27 +0000 Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1 Processing by UsersController#update as HTML Parameters: {"authenticity_token"=>"SFOI32GVPNt4UA1tZZMhHsDKAp64+FNWRv4kaJcJh4YA/isQx0nZyZWzHuKEmP8Z8h5+C7PPEcUvOUclxF3Iyw==", "user"=>{"nickname"=>"sample", "email"=>"sample@sample.com"}, "commit"=>"アカウント更新", "id"=>"3"} User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1 ↳ app/controllers/users_controller.rb:6:in `update' Rendering users/edit.html.erb within layouts/application Rendered shared/_second_header.html.erb (Duration: 5.3ms | Allocations: 641) Rendered shared/_footer.html.erb (Duration: 0.3ms | Allocations: 290) Rendered users/edit.html.erb within layouts/application (Duration: 9.4ms | Allocations: 1460) [Webpacker] Everything's up-to-date. Nothing to do Completed 200 OK in 94ms (Views: 86.1ms | ActiveRecord: 0.6ms | Allocations: 13423) Finished "/cable/" [WebSocket] for 172.20.0.1 at 2021-04-09 00:30:27 +0000 MessageChannel stopped streaming from message_channel Started GET "/cable" for 172.20.0.1 at 2021-04-09 00:30:27 +0000 Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1 Started GET "/cable/" [WebSocket] for 172.20.0.1 at 2021-04-09 00:30:27 +0000 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) MessageChannel is transmitting the subscription confirmation MessageChannel is streaming from message_channel
該当のソースコード
app/controllers/application_controller.rb
ruby
1class ApplicationController < ActionController::Base 2 before_action :configure_permitted_parameters, if: :devise_controller? 3 4 private 5 6 def configure_permitted_parameters 7 devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname]) 8 devise_parameter_sanitizer.permit(:account_update, keys: [:nickname]) #追加箇所 9 end 10end 11
app/controllers/users_controller.rb
ruby
1class UsersController < ApplicationController 2 def edit 3 end 4 5 def update 6 if current_user.update(user_params) 7 redirect_to root_path 8 else 9 render :edit 10 end 11 end 12 13 private 14 15 def user_params 16 params.require(:user).permit(:nickname, :email) 17 end 18end 19
app/views/users/edit.html.erb
ruby
1<%= render "shared/second_header" %> 2 3<%= form_with model: current_user, class: "form-main", local: true do |f|%> 4<div class="form-wrap"> 5 <div class="form-header"> 6 <h2 class="form-header-text"> 7 アカウント編集 8 </h2> 9 </div> 10 11 <div class="form-group"> 12 <div class="form-text-wrap"> 13 <label class="form-text">ニックネーム</label> 14 </div> 15 <%= f.text_field :nickname, class:"input-default", autofocus: true, placeholder:"例)席郎" %> 16 </div> 17 <div class="form-group"> 18 <div class="form-text-wrap"> 19 <label class="form-text">メールアドレス</label> 20 </div> 21 <%= f.email_field :email, class:"input-default", placeholder:"PC・携帯どちらでも可" %> 22 </div> 23 <div class="submit-btn"> 24 <%= f.submit "アカウント更新", class:"submit-btn-green" %> 25 </div> 26</div> 27<% end %> 28 29<%= render "shared/footer" %>
試したこと
DBを更新できないということは、許可できていないのではと思い__application_controller.rb__にdevise_parameter_sanitizer.permit(:account_update, keys: [:nickname])
の記述をしましたが更新できず。
それから、ActionCable導入後に確認したらユーザー情報を更新できなくなっていたので、それらしい記事を探しましたが見当たりませんでした。
補足情報(FW/ツールのバージョンなど)
Ruby 2.6.5
Rails 6.0.0
devise
あなたの回答
tips
プレビュー