解決したいこと
deviseの情報編集時にpasswordも含め全て更新できるようにしたい!
起っていること
Processing by Devise::RegistrationsController#update as HTML Parameters: {"authenticity_token"=>"pIrLVpiSyUzL85deQhLPrv/qD2Iig5XspxlIQBccx1zD9GrdMhRzxtgBxVpY9w5XpbJ0e0C5WeK0uuZEQibBQw==", "user"=>{"nickname"=>"テスラ", "email"=>"te@te", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "birthday(1i)"=>"1980", "birthday(2i)"=>"9", "birthday(3i)"=>"19", "gender_id"=>"2", "form_id"=>"2", "profession_name"=>"トレーナー", "want_to_do"=>"自分のジムを立ち上げたい\r\nSNSで拡散したいため、カメラマンに撮影して欲しい", "can_do_list"=>"姿勢改善、筋肉増量のためのトレーニング、食事指導"}, "commit"=>"変更する"} User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1 User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1 Rendering devise/registrations/edit.html.erb within layouts/application Rendered shared/_second-header.html.erb (Duration: 0.8ms | Allocations: 662) Rendered shared/_error_messages.html.erb (Duration: 0.3ms | Allocations: 156) Rendered shared/_second-footer.html.erb (Duration: 0.2ms | Allocations: 292) Rendered /Users/niimurakenta/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/devise-4.7.3/app/views/devise/shared/_links.html.erb (Duration: 0.2ms | Allocations: 78) Rendered devise/registrations/edit.html.erb within layouts/application (Duration: 3.8ms | Allocations: 4633) [Webpacker] Everything's up-to-date. Nothing to do Completed 200 OK in 583ms (Views: 19.2ms | ActiveRecord:
実際のコード
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? private def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname, :birthday, :gender_id, :form_id, :profession_name, :want_to_do, :can_do_list]) devise_parameter_sanitizer.permit(:account_update, keys: [:password, :nickname, :birthday, :gender_id, :form_id, :profession_name, :want_to_do, :can_do_list]) end end
class UsersController < ApplicationController before_action :authenticate_user!, except: [:index, :show] before_action :user_params_id, except: [:index,:new, :create] def index @users = User.all @users = User.search(params[:search]) end def show @user=User.find(params[:id]) @currentUserEntry=Entry.where(user_id: current_user.id) @userEntry=Entry.where(user_id: @user.id) if @user.id == current_user.id else @currentUserEntry.each do |cu| @userEntry.each do |u| if cu.room_id == u.room_id then @isRoom = true @roomId = cu.room_id end end end if @isRoom else @room = Room.new @entry = Entry.new end end end private def puser_params params.require(:user).permit(:nickname,:birthday,:gender_id, :form_id, :profession_name, :want_to_do, :can_do_list, :image) end def user_params_id @users = User.find(params[:id]) end end
<%= render "shared/second-header"%> <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> <div class='form-wrap'> <div class='form-header'> <h1 class='form-header-text'> 会員情報入力 </h1> </div> <%= render 'shared/error_messages', model: f.object %> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">ニックネーム</label> <span class="indispensable">必須</span> </div> <%= f.text_area :nickname, class:"input-default", id:"nickname", placeholder:"例) UNION太郎" %> </div> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">メールアドレス</label> <span class="indispensable">必須</span> </div> <%= f.email_field :email, class:"input-default", id:"email", placeholder:"PC・携帯どちらでも可", autofocus: true %> </div> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">パスワード</label> <span class="indispensable">必須</span> </div> <%= f.password_field :password, autocomplete: "current-password", class:"input-default", id:"password", placeholder:"6文字以上の半角英数字" %> <p class='info-text'>※英字と数字の両方を含めて設定してください</p> </div> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">パスワード(確認)</label> <span class="indispensable">必須</span> </div> <%= f.password_field :password_confirmation,class:"input-default", id:"password-confirmation", placeholder:"同じパスワードを入力して下さい" %> </div> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">生年月日</label> <span class="indispensable">必須</span> </div> <div class='input-birth-wrap'> <%= raw sprintf( f.date_select( :birthday, class:'select-birth', id:"birth-date", use_month_numbers: true, prompt:'--', start_year: 1930, end_year: (Time.now.year - 5), date_separator: '%s'), "<p> 年 </p>", "<p> 月 </p>") + "<p> 日 </p>" %> </div> </div> <%# /出品画像 %> <%# 商品名と商品説明 %> <div class="new-items"> <%= @user.nickname %> <div class="weight-bold-text"> 性別 <span class="indispensable">必須</span> </div> <%= f.collection_select(:gender_id, Gender.all, :id, :name, {}, {class:"select-box", id:"item-category"}) %> <div class="weight-bold-text"> 所属 <span class="indispensable">必須</span> </div> <%= f.collection_select(:form_id, Form.all, :id, :name, {}, {class:"select-box", id:"item-category"}) %> <div class="weight-bold-text"> 職業 <span class="indispensable">必須</span> </div> <%= f.text_area :profession_name, class:"items-text", id:"item-name", placeholder:"職業(必須 40文字まで)", maxlength:"40" %> <div class="items-explain"> <div class="weight-bold-text"> 叶えたいこと、やりたいこと <span class="indispensable">必須</span> </div> <%= f.text_area :want_to_do, class:"items-text", id:"item-info", placeholder:"叶えたいこと、やりたいことの説明(必須 1,000文字まで)(SNSでの集客、ホームページを作って欲しいなど)例)2010年頃に栃木でパーソナルジムをオープンしました。それに伴いSNSで集客を行いたいのでカメラマンの方を探しています。" ,rows:"7" ,maxlength:"1000" %> </div> <div class="items-explain"> <div class="weight-bold-text"> できることの説明 <span class="indispensable">必須</span> </div> <%= f.text_area :can_do_list, class:"items-text", id:"item-info", placeholder:"できることの説明(必須 1,000文字まで)(色、素材、重さ、定価、注意点など)例)2010年頃に1万円で購入したジャケットです。ライトグレーで傷はありません。あわせやすいのでおすすめです。" ,rows:"7" ,maxlength:"1000" %> </div> </div> <%# /商品名と商品説明 %> <%# 下部ボタン %> <div class="sell-btn-contents"> <%= f.submit "変更する" ,class:"sell-btn" %> <%=link_to 'もどる', root_path, class:"back-btn" %> </div> <%# /下部ボタン %> </div> <% end %> <%= render "shared/second-footer"%> <%= render "devise/shared/links" %>
Rails.application.routes.draw do devise_for :users resources :users, only: [:index,:show] root to: 'users#index' resources :messages, only: [:create] resources :rooms, only: [:create,:show] end
# frozen_string_literal: true class DeviseCreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| ## Database authenticatable t.string :nickname, null: false t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.date :birthday, null: false t.integer :gender_id, null: false t.integer :form_id, null: false t.string :profession_name, null: false t.string :want_to_do, null: false t.string :can_do_list, null: false ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable # t.integer :sign_in_count, default: 0, null: false # t.datetime :current_sign_in_at # t.datetime :last_sign_in_at # t.string :current_sign_in_ip # t.string :last_sign_in_ip ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true end end
ご確認宜しくの程お願い致します。