【问题标题】:undefined method `completed_at' for 2012-08-03 20:24:48 UTC:Time2012-08-03 20:24:48 UTC:Time 的未定义方法“completed_at”
【发布时间】:2012-08-04 00:40:51
【问题描述】:

这是错误消息及其应用程序跟踪:

NoMethodError in Shopping::OrdersController#index

(the root of error is the application directory.)
undefined method `completed_at' for 2012-08-03 20:24:48 UTC:Time

app/models/coupon.rb:44:in `eligible?'
app/models/coupon.rb:40:in `qualified?'
app/models/coupon.rb:34:in `value'
app/models/order.rb:276:in `coupon_amount'
app/models/order.rb:260:in `find_total'
app/models/order.rb:284:in `credited_total'
app/controllers/shopping/orders_controller.rb:100:in `form_info'
app/controllers/shopping/orders_controller.rb:21:in `index'

但是,当我选择查看完整跟踪时,第一行是

activesupport (3.2.7) lib/active_support/time_with_zone.rb:328:in `method_missing'

我不确定是控制器的问题还是 active_support 的问题。有人知道怎么修这个东西吗?谢谢!

在 coupon.rb 中

def qualified?(item_prices, order, at = nil)
  at ||= order.completed_at || Time.zone.now
  item_prices.sum > minimum_value && eligible?(at)
end

def eligible?(order, at = nil)
  at ||= order.completed_at || Time.zone.now
  starts_at <= at && expires_at >= at
end

谢谢。

【问题讨论】:

  • 没有任何上下文的错误,真的很难帮助你。
  • 问题出在你的coupon.rb L44方法合格吗? (参见堆栈跟踪)。您可能在不正确的对象上调用“completed_at”。
  • 是的,这个错误只有在我使用优惠券时才会出现。我添加了合格和合格的方法。谢谢!

标签: ruby-on-rails ruby controller activesupport


【解决方案1】:

coupon.rb 的第 44 行,您正在对 Time 对象调用 completed_at。我不知道这是您的代码中的哪一行,但这应该足以让您通过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-24
    • 2012-11-13
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多