NameError undefined局部变量或方法`current_period_end'

时间:2014-08-12 19:09:24

标签: ruby-on-rails

我尝试将Stripes current_period_end属性保存到Subscription表,但是我得到了一行self.cancellation_date = current_period_end

的NameError

Subscription.rb:

  attr_accessor :stripe_card_token, :paypal_payment_token, :cancellation_date

 def save_with_stripe_payment
    customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
    self.stripe_customer_token = customer.id
    self.cancellation_date = current_period_end
    save!
  rescue Stripe::InvalidRequestError => e
    logger.error "Stripe error while creating customer: #{e.message}"
    errors.add :base, "There was a problem with your credit card."
    false
  end

1 个答案:

答案 0 :(得分:1)

ASAIK current_period_end应该是订阅对象的属性。所以它可能像

customer.subscription.current_period_end

修改

在查看关于客户对象的Stripe API文档(https://stripe.com/docs/api/ruby#customer_object)之后,我重申订阅实际上是一个订阅对象数组。所以你实际上需要知道要获得哪个订阅,但她的样本可以使用

customer.subscriptions.first.current_period_end

哪个会进行第一次订阅并进行检查。实际上,您可能想要获取最新的(subscriptions.last)