【发布时间】:2016-10-04 01:47:24
【问题描述】:
我不想让用户更新他们的:name。我找到了这个question for Rails version 3,但答案对我不起作用。我正在使用 Rails 4。我可能只是语法错误。我无法让@user.update_attributes(params[:user]) 工作。仅限:@user.update_attributes(user_params)。我的编辑表单中没有包含:name,但我的理解(??)是用户仍然可以自己通过浏览器传递它,并且使用我当前的代码他们可以更改:name。
class UsersController < ApplicationController
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
@user.update_attributes(user_params)
if @user.save
flash[:success] = "Profile updated"
redirect_to @user
else
flash[:danger] = "Profile update Unsuccessful"
redirect_to 'edit'
end
end
private
def user_params
params.require(:user).permit(:name, :email, :email_confirmation, :password, :password_confirmation)
end
【问题讨论】:
标签: ruby-on-rails