0

我正在使用条纹工作我的第一个项目。我有一个订阅产品,我已经获得了基本的条带功能性,但我需要将数据库中的用户记录更新为“订阅”,以便在开发中稍后使用它作为验证。我在网上看到了几个教程,其中显示在您的模型中添加了一个名为订阅的专栏或沿着这些专栏的一些专栏,并在条带化客户创建过程中对其进行更新。我有这个工作,除非它不更新我的用户模型(在这种情况下,供应商)。这里是我的条纹PROCESSS控制器:条纹 - 不更新数据库中的用户信息

class ChargesController < ApplicationController 
    before_filter :authenticate_supplier! 

    def new 
    end 

    def create 
     # Amount in cents 
     token = params[:stripeToken] 

     customer = Stripe::Customer.create(
      :source => token, # obtained from Stripe.js 
      :plan => "Free_month_annual", 
      :email => current_supplier.email, 
      #:coupon => "coupon_ID" 
     ) 

     current_supplier.subscribed = true 
     #current_supplier.stripe_id = token 

     redirect_to orders_path 

    rescue Stripe::CardError => e 
     flash[:error] = e.message 
     redirect_to charges_path 
    end 

end 

正如你可以看到,有评论说两件事情 - 优惠券,我打算以后的工作,并stripe_id更新,因为我遇到了一个错误在已经使用了token一次(不能使用它两次)。我已经更新了我的供应商模型,数据库中有适当的列,参数已更新为允许supplier.subscribed。我确信这对很多人来说都是一个快速的答案,但我需要帮助来发现我的问题。

编辑: 订阅是一个布尔场 - FYI

回答

1

看来你忘了保存current_supplier记录。

的解决方案应该添加类似:

current_supplier.subscribed = true 
#current_supplier.stripe_id = token 

current_supplier.save! 

redirect_to orders_path 
+0

问题解决了 - 谢谢。之前我已经'保存!',但是出现了一个错误(因为我没有引用current_supplier,所以现在忘记了)并删除了它。无法看到我认为树木的森林... – PSCampbell