発生している問題・エラーメッセージ
エラーメッセージ param is missing or the value is empty: user private def user_params params.require(:user).permit(:name) *エラー箇所 end Request parameters {"_method"=>"delete", "authenticity_token"=>"云々", "controller"=>"users", "action"=>"destroy", "id"=>"2"}
該当のソースコード
routes
1Rails.application.routes.draw do 2 devise_for :users 3 root to: "posts#index" 4 5 resources :users, only: [:show, :edit, :update, :destroy] 6 resources :friends, only: [:create, :destroy] 7 resources :posts, only: [:index, :new, :create] 8 9 resources :users do 10 member do 11 get :following, :followers 12 end 13 end 14end
db
1class DeviseCreateUsers < ActiveRecord::Migration[6.0] 2 def change 3 create_table :users do |t| 4 ## Database authenticatable 5 t.string :email, null: false, default: "" 6 t.string :encrypted_password, null: false, default: "" 7 t.string :name, null: false 8以下省略
model
1class User < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6 7 has_many :posts 8 has_many :active_friends, class_name: "Friend", 9 foreign_key: "follower_id", 10 dependent: :destroy 11 has_many :passive_friends, class_name: "Friend", 12 foreign_key: "followed_id", 13 dependent: :destroy 14 15 has_many :following, through: :active_friends, source: :followed 16 has_many :followers, through: :passive_friends, source: :follower 17 18 def follow(other_user) 19 following << other_user 20 end 21 22 def unfollow(other_user) 23 active_friends.find_by(followed_id: other_user.id).destroy 24 end 25 26 def following?(other_user) 27 following.include?(other_user) 28 end 29 30 validates :name, presence: true 31end
controller
1class UsersController < ApplicationController 2 def show 3 @user = User.find(params[:id]) 4 end 5 6 def edit 7 end 8 9 def update 10 if current_user.update(user_params) 11 redirect_to root_path 12 else 13 render :edit 14 end 15 end 16 17 def destroy 18 if current_user.destroy(user_params) 19 redirect_to root_path 20 else 21 render :edit 22 end 23 end 24 25 def following 26 @title = "Following" 27 @user = User.find(params[:id]) 28 @users = @user.following 29 render 'show_follow' 30 end 31 32 def followers 33 @title = "Followers" 34 @user = User.find(params[:id]) 35 @users = @user.followers 36 render 'show_follow' 37 end 38 39 private 40 def user_params 41 params.require(:user).permit(:name) 42 end 43end
views
1<h2>Edit Account</h2> 2<h5>アカウントの編集</h5> 3 4<div> 5 <%= form_with model: current_user, local: true do |f|%> 6 <%= f.label :name %> 7 <%= f.text_area :name, autofocus: true %> 8 <%= f.submit "Update", class: 'btn'%> 9 <% end %> 10</div> 11 12<%= link_to "アカウントを削除する", current_user, method: :delete %> 13<%= link_to "マイページに戻る", :back %>
views
1<h2>Sign up</h2> 2 3<%= form_with model: @user, url: user_registration_path, class: 'registration-main', local: true do |f| %> 4 <%= render "devise/shared/error_messages", resource: resource %> 5 6 <div class="field"> 7 <%= f.label :name %><br /> 8 <%= f.text_area :name, autofocus: true, autocomplete: "name" %> 9 </div> 10 11 <div class="field"> 12 <%= f.label :email %><br /> 13 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 14 </div> 15 16 <div class="field"> 17 <%= f.label :password %> 18 <% if @minimum_password_length %> 19 <em>(<%= @minimum_password_length %> characters minimum)</em> 20 <% end %><br /> 21 <%= f.password_field :password, autocomplete: "new-password" %> 22 </div> 23 24 <div class="field"> 25 <%= f.label :password_confirmation %><br /> 26 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 27 </div> 28 29 <div class="actions"> 30 <%= f.submit "Sign up" %> 31 </div> 32<% end %> 33 34<%= render "devise/shared/links" %> 35
補足情報(FW/ツールのバージョンなど)
以前削除の件で解決したかに思われましたが、実際は解決していなかったようです。
エラーが出るタイミングとしてはuserを削除するタイミングです。
request_parameterに:nameがないのが気になるのですが、エラーに関係あるでしょうか?
エラー解決のためレビューのほどよろしくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2021/08/30 15:04
2021/08/30 15:36
退会済みユーザー
2021/08/30 16:19
2021/08/30 21:21
2021/09/03 09:31
退会済みユーザー
2021/09/03 09:56