如何使用与gem同名的模型?

时间:2017-05-26 18:17:59

标签: ruby-on-rails namespaces

我看到了这个问题,但它没有帮助:What is the fully qualified name of a model in Ruby on Rails?

我有这段代码

RefreshRequested

Stripe是一颗宝石,但它也是我模特的名字。我在上面尝试了# create Stripe customer customer = Stripe::Customer.create(:email => @user.email, :source => params['subscription']['token']) stripe_subscription = Stripe::Subscription.create(:customer => customer.id, :plan => @subscription.plan) stripe = ::Stripe.new subscription: @subscription, customer_id: customer.id, plan_id: @subscription.plan, stripe_subscription_id: stripe_subscription.id, last_paid: Time.now, status: stripe_subscription.status ,我也尝试了::Stripe.new。他们都给出了错误

  

未定义的方法`new' for Stripe:Module

1 个答案:

答案 0 :(得分:1)

你不能。顶级命名空间中不能存在同名的模块和类。如果您实际 让Rails加载Stripe模块,那么您的应用会因类型错误而崩溃,并抱怨您已尝试更改Stripe的类型从模块到类。