Ruby:ArgumentError(错误的参数数量(给定1,预期0))[关闭]

mi7gmzs6  于 12个月前  发布在  Ruby
关注(0)|答案(2)|浏览(115)

已关闭此问题为not reproducible or was caused by typos。它目前不接受回答。

此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这一个是解决的方式不太可能帮助未来的读者。
18天前关闭
Improve this question
很明显,我根本不理解如何在Rails中传递参数和调用方法。
我尝试使用虚拟信息对stripe进行测试调用,当我尝试从控制台运行此命令时,我得到了主题错误:

Stripe::CustomerApi.new(30).create_stripe_customer

方法所在的类如下:

require 'stripe'
module Stripe
    class CustomerApi

        def initialize(id)
          @user = User.find(id)
          @company_profile = @user.company_profile
          Stripe.api_key = 'my test key info'
        end

        def create_stripe_customer
          request = Stripe::Customer.create({
              email: '[email protected]',
              name: 'john doe',
              address: {
                city: 'Brothers',
                country: 'US',
                line1: '27 Any Street',
                postal_code: '90210',
                state: 'CA',
              }
            })

          Rails.logger.info request

        end
    end
end

这里的想法是,一旦我让测试工作,我将通过id值传递实际的用户信息。
从rails控制台添加堆栈跟踪。

irb(main):001:0> Stripe::CustomerApi.new(30).create_stripe_customer
  User Load (7.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 30], ["LIMIT", 1]]
  CompanyProfile Load (2.7ms)  SELECT  "company_profiles".* FROM "company_profiles" WHERE "company_profiles"."user_id" = $1 LIMIT $2  [["user_id", 30], ["LIMIT", 1]]
Traceback (most recent call last):
        3: from (irb):1
        2: from app/services/stripe/customer_api.rb:15:in `create_stripe_customer'
        1: from app/services/stripe/stripe_client.rb:11:in `initialize'
ArgumentError (wrong number of arguments (given 1, expected 0))

跟踪引用了stripe_client文件,我不知道为什么。这是一个单独的文件,我试图在其中使用REST API进行相同的API调用。它没有相同的方法。

mm5n2pyu

mm5n2pyu1#

我假设这两个文件的文件夹结构不同,并且两个文件的名称不同。我在本地计算机上运行您的代码,文件夹结构为app/services/stripe/customer_API.rb
当我运行下面提到的命令时,这段代码运行得很好,你应该尝试同样的命令。
Stripe::CustomerApi.new(1).create_stripe_customer

v440hwme

v440hwme2#

我是个白痴。堆栈跟踪显示如下:

from app/services/stripe/stripe_client.rb:11:in `initialize'

我在同一个文件夹中的两个不同文件上调用了两个初始化方法。我猜这是个禁忌我删除了我不使用的方法,它测试了SAT。

相关问题