2017-08-04 187 views
1

我在我的应用程序中有一个计划模型。有时我遇到以下错误。重新启动服务器后,它会消失一段时间。PayPal-Ruby-SDK模型名称冲突

宝石版本(1.6.0)

如何修复?

NoMethodError in Subscriptions#index

undefined method `map' for #<PayPal::SDK::REST::DataTypes::PlanList:0x007fbc494c13c0> 
Did you mean? tap 

-

Rendering subscriptions/index.html.erb within layouts/application 
    Rendered subscriptions/index.html.erb within layouts/application (3.3ms) 
Completed 500 Internal Server Error in 2145ms (ActiveRecord: 8.3ms) 



ActionView::Template::Error (undefined method `map' for #<PayPal::SDK::REST::DataTypes::PlanList:0x007fbc494c13c0> 
Did you mean? tap): 
    7:  <div class="field"> 
    8:   <p class="control has-icons-left is-expanded"> 
    9:   <%= form.input_field :plan_id, 
    10:   collection: @plans.map {|plan| ["#{plan.name} - $#{plan.cost}", plan.id]}, 
    11:   wrapper_html: { class: ' select is-fullwidth' }, class: 'input', label: false, prompt: 'Select a plan' %> 
    12:   <span class="icon is-small is-left"> 
    13:    <i class="fa fa-bars"></i> 

app/views/subscriptions/index.html.erb:10:in `block in _app_views_subscriptions_index_html_erb___836818763133109538_70223330120860' 
app/views/subscriptions/index.html.erb:2:in `_app_views_subscriptions_index_html_erb___836818763133109538_70223330120860' 

订阅控制器索引操作

def index @plans = Plan.all end

Web控制台

enter image description here

+0

您能否给我们实施您的计划对象? – romainsalles

+0

@romainsalles它只有2行'has_many:subscriptions'和 'has_many:users,through::subscriptions'。这不是关于包含枚举,因为它在重新启动服务器后工作正常。 – kirqe

+1

我不知道PayPal宝石。但看看文档,我认为你应该尝试调用'Plan.all.members'或'Plan.all.to_hash'并看看你在那里得到了什么。因为'Plan.all'不返回一个数组而是一个'PlanList'对象(@see:https://github.com/paypal/PayPal-Ruby-SDK/blob/master/lib/paypal-sdk/rest /data_types.rb#L2055) – romainsalles

回答

0

使用名称空间而不是包含模块可以解决问题。

PayPal::SDK::REST::Payment