为什么我的服务没有被正确声明?

我正在使用Stripe为我的应用创建付款服务。 我有:

#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 

在我的控制器中我试图运行它:

 #app/controller/subscriptions_controller.rb class SubscriptionsController < ApplicationController rescue_from PaymentGateway::CreateSubscriptionServiceError do |e| redirect_to root_path, alert: e.message end 

当我运行我的代码我得到这个错误:

 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应该能够正确加载类。