I have a private method like this for a registration form which has four fields, firstname
, email
, password
and confirm password
. I am not sure how to check for password confirmation
.
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
Previously, i was using the below code.How do i convert the code below to use params.require
User.new(name: params[:name], email: params[:email],
password: params[:password], confirmpassword: params[:password])
Looking at your code
User.new(name: params[:name], email: params[:email],
password: params[:password], confirmpassword: params[:password])
I suspect that you're not using password_confirmation
field. In that case, this is how you will use params.require
def user_params
params.require(:name)
params.require(:email)
params.require(:password)
params.permit(:name,:email,:password)
end
UPDATED AS PER COMMENT
if you are using password_confirmation
field, then this should be like in RAILS 3.x.x
User.new(name: params[:name], email: params[:email],
password: params[:password], confirmpassword: params[:password_confirmation])
And, this is how it will be with strong_parameters
(usually with rails 4.x.x)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With