本文介绍了为什么我的服务没有被正确声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Stripe 为我的应用创建支付服务.我有:
Im creating a Payment Service for my app with Stripe. I have:
#app/services/service_error.rb
class PaymentGateway::ServiceError < StandardError
attr_reader :exception_message
def initialize(message, exception_message: )
# Call the parent's constructor to set the message
super(message)
# Store the exception_message in an instance variable
@exception_message = exception_message
end
end
class PaymentGateway::CreateSubscriptionServiceError < PaymentGateway::ServiceError
end
在我的控制器中我试图运行它:
And in my controller im trying to run it:
#app/controller/subscriptions_controller.rb
class SubscriptionsController < ApplicationController
rescue_from PaymentGateway::CreateSubscriptionServiceError do |e|
redirect_to root_path, alert: e.message
end
当我运行我的代码时出现此错误:
When I run my code Im getting this error:
ActionController::RoutingError (uninitialized constant PaymentGateway::CreateSubscriptionServiceError):
我在这里做错了什么?
推荐答案
正确的路径如下所示:
# app/services/payment_gateway/service_error.rb
class PaymentGateway::ServiceError < StandardError
end
# app/services/payment_gateway/create_subscription_service_error.rb
class PaymentGateway::CreateSubscriptionServiceError < PaymentGateway::ServiceError
end
ActiveSupport 应该能够正确加载类.
ActiveSupport should be able to load classes correctly then.
这篇关于为什么我的服务没有被正确声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!