错误:没有路由匹配[GET]" / cgi-bin / webscr"

时间:2016-01-22 01:09:43

标签: ruby-on-rails paypal paypal-sandbox

我正在尝试使用基本的Paypal来资助Rails众筹项目中的任务。当我点击特定任务的基金按钮时,我创建了一个新的资金表格,可以节省用户选择的资金,等等。然而,在新的筹资行动中,当用户点击基金时,我希望Paypal处理资金。然而, 我目前收到的错误是:"没有路线匹配[GET]" / cgi-bin / webscr"

这是我的资金控制人:

class FundingsController < ApplicationController
def new
if params[:todo_item_id]
  @todo_item = TodoItem.find(params[:todo_item_id])
  @funding =  Funding.new
  #(todo_item: @todo_item, user_id: current_user.id)
  raise ActiveRecord::RecordNotFound if @todo_item.nil?
end

end

def create
  @funding = Funding.new(funding_params)
if @funding.save
  redirect_to @funding.paypal_url(funding_path(@funding))
else
  render :new
end
end


protect_from_forgery except: [:hook]
def hook
params.permit! # Permit all Paypal input params
status = params[:payment_status]
if status == "Completed"
  @funding = Funding.find params[:invoice]
  @funding.update_attributes notification_params: params, status: status, transaction_id: params[:txn_id], funded_at: Time.now
 end
 render nothing: true
 end


private

def funding_params
  params.require(:funding).permit(:todo_item_id, :user_id, :amount)
end
end

这是我的资助模式:

 class Funding < ActiveRecord::Base
 has_one :card
 belongs_to :todo_item
 has_one :user

 accepts_nested_attributes_for :card

def payment_method
if card.nil? then "paypal"; else "card"; end
end
serialize :notification_params, Hash
def paypal_url(return_path)
values = {
    business: "mybusinesssandbox@gmail.com",
    cmd: "_xclick",
    upload: 1,
    return: "#{Rails.application.secrets.app_host}#{return_path}",
    invoice: id,
    amount: self.amount,
    item_name: self.todo_item.content,
    item_number: self.todo_item.id,
    quantity: '1',
    notify_url: "#{Rails.application.secrets.app_host}/hook"
}
"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
 end
 end

我不确定为什么这种路由对我不起作用。另外,这是我的 app / views / fundings / new.html.erb:

  <h1><strong>Task:</strong> <%=@todo_item.content%><br>
  <strong>Project:</strong> <%= @todo_item.todo_list.title%> </h1>
  <%= form_for @funding, method: :post do |f| %>
  <%= f.hidden_field :todo_item_id, value: @todo_item.id %>
  <%= f.hidden_field :user_id, value: current_user.id %>
  <%= f.label :amount, "Amount you wish to donate in $" %>
  <%= f.number_field :amount %>
  <%= submit_tag "Fund", class: 'btn btn_primary' %>
  <%= link_to "Cancel", todo_list_path(@todo_item.todo_list_id, @todo_i), class: 'btn' %><br>
  <%end%>

我在哪里弄错了?

1 个答案:

答案 0 :(得分:1)

  

&#34;没有路线匹配[GET]&#34; / cgi-bin / webscr&#34;

您正在向您的服务器请求此资源,而不是Paypal。重新检查:

"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query

Rails.application.secrets.paypal_host可能是空白的!