Ruby on rails 如何在rails 4中使用params.require

Ruby on rails 如何在rails 4中使用params.require,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我有一个类似这样的私人方法用于注册表单,它有四个字段,名字,电子邮件,密码和确认密码。我不知道如何检查密码确认 def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end 以前,我使用的是下面的代码。如何将下面的代码转换为使用params.require User.new(name: params[:name], em

我有一个类似这样的私人方法用于注册表单,它有四个字段,
名字
电子邮件
密码
确认密码
。我不知道如何检查
密码确认

def user_params
    params.require(:user).permit(:name, :email, :password, 
               :password_confirmation)
end
以前,我使用的是下面的代码。如何将下面的代码转换为使用params.require

User.new(name: params[:name], email: params[:email], 
     password: params[:password], confirmpassword: params[:password])
查看您的代码

User.new(name: params[:name], email: params[:email], 
     password: params[:password], confirmpassword: params[:password])
我怀疑您没有使用密码确认字段。在这种情况下,您将使用
params.require

def user_params
    params.require(:name)
    params.require(:email)
    params.require(:password)
    params.permit(:name,:email,:password)
end
根据评论更新

如果您使用的是
password\u confirmation
字段,那么这应该类似于RAILS 3.x.x

User.new(name: params[:name], email: params[:email], 
     password: params[:password], confirmpassword: params[:password_confirmation])
User.new(user_params)

def user_params
    params.require(:name)
    params.require(:email)
    params.require(:password)
    params.require(:confirm_password)
    params.permit(:name,:email,:password,:confirm_password)
end
这就是使用
strong\u参数时的情况(通常使用rails 4.x.x


我有一个密码确认字段?在这种情况下,您可以将
password\u confirmation
字段列为白名单,就像
password
Perfect一样,所以在我的情况下应该是:confirm\u password right?“我的名字”字段为“确认”_password@theJava你应该明确你的域名是
confirm\u password
。目前你说的是
confirm password
。你的域名是
confirmpassword
?然后,如果您想
白名单
它,您必须这样做
参数require(:user).permit(:name,:email,:password,:confirmpassword)