【发布时间】:2021-07-13 17:43:01
【问题描述】:
在使用邮递员创建新用户时,我收到以下错误:
新建用户失败:验证失败:名字不能为空,Email不能为空,Email无效;参数:{:email=>nil, :first_name=>nil, :last_name=>nil, :plan=>"Basic", :role=>"requester_readonly", :phone_number=>nil, :ip=>nil, : company_name=>nil, :product_id=>2, :user_reference_id=>nil, :handle=>nil}
邮递员错误:
{
"error": [
"First name can't be blank",
"Email can't be blank",
"Email is invalid"
],
"status": 400
}
我将以下值传递给邮递员中的参数:
{
"email": "customer@yahoo.com",
"firstName": "Demo",
"lastName": "Customer",
"password": "Password_0",
"phoneNumber": "0123456789",
"ip": "10.10.2.125",
"company": "xyz"
}
这是用户注册的功能:
def register
product_id = $product_id
if params[:plan]
@plan = AppCommon::Plan.where(name: params[:plan], product_id: product_id).first
end
@plan = @plan || AppCommon::Plan.find_default(product_id)
form_params = {email: params[:email], first_name: params[:firstName], last_name: params[:lastName], password: params[:password], plan: @plan.name, role: 'requester_readonly', phone_number: params[:phoneNumber], ip: params[:ip], company_name: params[:company], product_id: product_id, user_reference_id: params[:referenceId]}
service = Web::UserCreater.new(form_params)
result = service.perform
@user = service.user
if result.success?
render json: {status: 200, authentication_token: @user.authentication_token}
else
error_response(@user.errors.full_messages.to_a)
end
end
【问题讨论】:
-
你能发布日志文件中的实际参数吗?
标签: ruby-on-rails validation postman