ActiveRecord VerificationsController#create 找不到具有 'id'= (paypal, current_user) 的用户
Posted
技术标签:
【中文标题】ActiveRecord VerificationsController#create 找不到具有 \'id\'= (paypal, current_user) 的用户【英文标题】:ActiveRecord VerificationsController#create Couldn't find User with 'id'= (paypal, current_user)ActiveRecord VerificationsController#create 找不到具有 'id'= (paypal, current_user) 的用户 【发布时间】:2016-10-19 19:38:42 【问题描述】:我无法让 PayPal 进行验证!我一定有这么小的东西是错误的!!。
VerificationsController#create 中的 ActiveRecord::RecordNotFound 找不到具有 'id'=
的用户我的错误日志:
Processing by VerificationsController#create as
Parameters: "utf8"=>"✓", "authenticity_token"=>"SPz+2H/uCUrSnUlvorZ2hIu9hXVa6t8x9fzvs5NqKIZEgsXQmf8WDjwbTG0Fm0/5OnISBksXwV/6RYDuL9kS2g==", "verification"=>"paypal_email"=>"vampiricbeef@gmail.com", "paypal_firstname"=>"", "paypal_lastname"=>"", "commit"=>"verify", "id"=>"3"
User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY created_at DESC
User Load (0.3ms) SELECT "users".* FROM "users"
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 3]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", nil]]
Completed 404 Not Found in 19ms (ActiveRecord: 2.0ms)
ActiveRecord::RecordNotFound (Couldn't find User with 'id'=):
app/controllers/verifications_controller.rb:7:in `create'
验证控制器:
def create
@user = User.find(params[:user_id])
# @verification = current_user.verification.create(verification_params)
@verification = current_user.create_verification(verification_params)
require 'paypal-sdk-adaptiveaccounts'
@api = PayPal::SDK::AdaptiveAccounts::API.new( :device_ipaddress => "127.0.0.1" )
# Build request object
@get_verified_status = @api.build_get_verified_status(
:emailAddress => "current_user.verification.paypal_email",
:matchCriteria => "NONE" )
# Make API call & get response
@get_verified_status_response = @api.get_verified_status(@get_verified_status)
# Access Response
if @get_verified_status_response.success?
@get_verified_status_response.accountStatus
@get_verified_status_response.countryCode
@get_verified_status_response.userInfo
else
@get_verified_status_response.error
end
status = params[:accountStatus]
verification = Verification.find(params[:emailAddress])
if status != "VERIFIED" || @get_verified_status_response.error
redirect_to edit_user_registration_path(current_user)
verification.update_attributes paypal_verified: false
verification.destroy
elsif status == "VERIFIED"
redirect_to edit_user_registration_path(current_user)
verification.update_attributes paypal_verified: true
else
redirect_to edit_user_registration_path(current_user)
verification.update_attributes paypal_verified: false
verification.destroy
end
end
private
def verification_params
params.require(:verification).permit(:user_id, :paypal_firstname, :paypal_lastname, :paypal_email, :paypal_verified)
end
用户控制器
def paypal_verification
# @verification = @user.verification.new
@user = current_user
@verification = current_user.verification
# @verification = Verification.create(params[:verification])
@user.verification = @verification
end
paypal_verification.html.erb(这是您单击提交然后运行 VerificationsController 的表单页面)
<% if current_user.verification != nil %>
<h>edit</h>
<%= form_for(@user.verification, url: user_verifications_path(@user, @user.verification)) do |f| %>
<%= f.email_field :paypal_email, :class => 'form-control', :placeholder => "Paypal Email", id: 'Pemail' %>
<%= f.text_field :paypal_firstname, :class => 'form-control', :placeholder => "Paypal FirstName", id: 'PfirstName' %>
<%= f.text_field :paypal_lastname, :class => 'form-control', :placeholder => "Paypal LastName", id: 'PlastName' %>
<%= f.submit "verify", class: "btn btn-primary" %>
<% end %>
<% else %>
<%= form_for(Verification.new, url: user_verifications_path(@user)) do |f| %>
<%= f.email_field :paypal_email, :class => 'form-control', :placeholder => "Paypal Email", id: 'Pemail' %>
<%= f.text_field :paypal_firstname, :class => 'form-control', :placeholder => "Paypal FirstName", id: 'PfirstName' %>
<%= f.text_field :paypal_lastname, :class => 'form-control', :placeholder => "Paypal LastName", id: 'PlastName' %>
<%= f.submit "verify", class: "btn btn-primary" %>
<% end %>
<% end %>
【问题讨论】:
【参考方案1】:在GetVerifiedStatus API中,参考https://developer.paypal.com/docs/classic/api/adaptive-accounts/GetVerifiedStatus_API_Operation/?mark=GetVerifiedStatus
firstName 、 lastName 和 matchCriteria 是必填字段。 matchCriteria=NONE 选项仅适用于某些金融机构。
请尝试设置 firstname,lastname 和 matchCriteria=NAME ,然后重试。
【讨论】:
以上是关于ActiveRecord VerificationsController#create 找不到具有 'id'= (paypal, current_user) 的用户的主要内容,如果未能解决你的问题,请参考以下文章
在哪里添加参数到 Route:verification.notice language/email/verify
用户中的 NoMethodError#paypal_verification
ssh登录出现 Host key verification failed. 问题
CSRF verification failed. Request aborted. 解决方法