ActiveRecord VerificationsController #crea找不到'id'的用户=(paypal,current_user)

时间:2016-06-17 21:17:29

标签: ruby-on-rails database forms paypal controller

我遇到麻烦让PayPal验证!!我必须有一些小的东西错误!!。

VerificationsController中的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'

verificationsController:

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

UsersController

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 个答案:

答案 0 :(得分:0)

在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,然后重试。