下記のコードにおいて、def update
でundefined method 'update' for nil:NilClass
というエラーが出るのですが、どうすれば解決できますでしょうか?
@user
に値が入っていないか、profile_params
から値が渡ってきていないかのどちらかだと思うのですが、どうすれば解決できるのかがわかりません。
よろしくお願いします。
追記:if @user.update(profile_params)
のupdate
をsave
に変えても同じエラーが出ました。
↓profile_controller.rb
class ProfilesController < ApplicationController def edit @profile = current_user end def update @profile = current_user if @user.update(profile_params) flash[:success] = '更新しました' redirect_to @user else flash.now[:danger] = '更新できませんでした' render :edit end end private def profile_params params.require(:user).permit(:name, :comment) end end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。