現在ユーザー編集ができるように設定しているのですが、編集画面から、updateボタンを押しても画面遷移せず、テーブルに保存もされないという状況です。特にエラーは出ていません。
<コントローラー>
class UsersController < ApplicationController
before_action :authenticate_user!,only:[:show]
def show
@user = User.find(params[:id])
@recipes =@user.recipes
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update(user_params) redirect_to user_path(@user) else render :edit end
end
private
def user_params
params.require(:user).permit(:name,:email)
end
end
<ビュー>
<モデル>
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
with_options presence:true do
validates :name
EMAIL = /\A[\w+-.]+@[a-z\d-.]+.[a-z]+\z/i
validates :email, format: {with: EMAIL}
validates :password,format: {with:/\A(?=.?[a-z])(?=.?\d)[a-z\d]+\z/i, message: 'Include both letters and numbers'}
end has_many :recipes,dependent: :destroy has_many :goods has_many :comments,dependent: :destroy def already_gooded?(recipe) self.goods.exists?(recipe_id: recipe.id) end
end
ターミナルでupdateアクションの部分にbinding.pryを挿入し、確認してみたのですが、user_paramsの中身も取れているのですが、updateされないのですが、ご回答いただける方いらっしゃいますでしょうか?
あなたの回答
tips
プレビュー