我保证我已经查看了所有相似的答案,但我是Rails的新手,并且不知道我在做什么。总之...
我有UsersController
方法customer
。我不知道这种方法是否有效,我还没有看到它弹出的错误。
64 def customer
65 begin
66 customer = Stripe::Customer.retrieve("hardcodedidfornow")
67 rescue Stripe::StripeError => e
68 status 402
69 return "Error retrieving customer: #{e.message}"
70 end
71 status 200
72 content_type :json
73 customer.to_json
74 end
我在路线中定义了这种方法
namespace :api do
namespace :v1 do
resources :users, only: [:index, :create, :show, :update, :destroy] do
member do
get :customer
end
end
end
end
然后我在我的iOS应用程序中使用GET在此路由中调用它而没有额外的参数
http://baseurl.com/api/v1/users/theuserid/customer
我总是得到内部服务器错误500,当我检查日志时,它说错误的参数数量(1表示0)。
Processing by Api::V1::UsersController#customer as JSON
2016-10-07T05:04:59.087546+00:00 app[web.1]: Started GET "/api/v1/users/5/customer" for 162.237.102.13 at 2016-10-07 05:04:59 +0000
2016-10-07T05:04:59.135976+00:00 app[web.1]: Parameters: {"id"=>"5", "user"=>{}}
2016-10-07T05:04:59.568989+00:00 heroku[router]: at=info method=GET path="/api/v1/users/5/customer" host=someapp.herokuapp.com request_id=7f0f76bd-4577-40b0-9eb6-265787cf3d5c fwd="162.237.102.13" dyno=web.1 connect=0ms service=496ms status=500 bytes=259
2016-10-07T05:04:59.578541+00:00 app[web.1]:
2016-10-07T05:04:59.577583+00:00 app[web.1]: Completed 500 Internal Server Error in 441ms (ActiveRecord: 3.7ms)
2016-10-07T05:04:59.578543+00:00 app[web.1]: ArgumentError (wrong number of arguments (1 for 0)):
2016-10-07T05:04:59.578544+00:00 app[web.1]: app/controllers/api/v1/users_controller.rb:71:in `customer'
所以我想我正在寻找一个解决方案,但也要了解我哪里出错了所以我将来可以更好地处理这个问题。
谢谢!