2016-09-01 7 views
0

ここに投稿すると、おそらく明らかに何かが不足しています。私が受けている:Koudoku:NoMethodError on User Model

A NoMethodError occurred in webhook#event: 

undefined method 'cancel' for #<User:0x0000000a0b7520> 
    vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/attribute_methods.rb:407:in `method_missing' 

完全なトレースがhereです。そしてstripe_event.rbからのコードの関連するブロックがある:

events.subscribe 'customer.subscription.deleted' do |event| 
    stripe_id = event.data.object['customer'] 
    subscription = ::Subscription.find_by_stripe_id(stripe_id) 
    subscription.subscription_owner.try(:cancel) 
end 

Userモデルに:cancelを呼び出そうとしているようしかし、それは見えます - なぜそれはそれを行うだろうか? :cancelのメソッドを持っているSubscriptionsController(here、行131)で呼び出すべきではありませんか?

答えて

0

イベントをトリガするコントローラである可能性がありますが、トリガソースから独立していくつかのアクションについてイベントのアイデアを通知する必要があります。

このイベントを使用して、実行するコードを追加できます。

events.subscribe 'customer.subscription.deleted' do |event| 
    # get the "stripe ID" from event data 
    stripe_id = event.data.object['customer'] 
    # find the corresponding Subscription using this ID 
    subscription = ::Subscription.find_by_stripe_id(stripe_id) 
    # try to call cancel on the owner (a User) of that subscription 
    subscription.subscription_owner.try(:cancel) 
end