【发布时间】:2018-01-12 10:07:33
【问题描述】:
我的应用中有一个计划模型。有时我会遇到以下错误。重新启动服务器后它会消失一段时间。
宝石版(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
网络控制台
【问题讨论】:
-
你能给我们你的计划对象的实现吗?
-
@romainsalles 它只有两行
has_many :subscriptions和has_many :users, through: :subscriptions。这不是要包括可枚举的,因为它在重新启动服务器后可以正常工作。 -
我不知道 PayPal Gem。但是查看文档,我认为您应该尝试致电
Plan.all.members或Plan.all.to_hash并查看其中的内容。因为Plan.all不返回一个数组而是一个PlanList对象(@see: github.com/paypal/PayPal-Ruby-SDK/blob/master/lib/paypal-sdk/…) -
@romainsalles 我注意到如果我打错字并保存它然后重新加载我的浏览器并出现错误,然后修复拼写错误并再次重新加载浏览器我会收到此错误。所以这可能是弹簧预加载器的问题。
Plan.all.to_hash返回一个空哈希 -
Plan.all.each方法似乎也有效:controller = github.com/samuelsimoes/rails-paypal-subscriptions-sample/blob/…, view = github.com/samuelsimoes/rails-paypal-subscriptions-sample/blob/…
标签: ruby-on-rails ruby paypal paypal-rest-sdk