使用Stripe的订阅表单未正确传递参数

我在我的Rails 4.2应用程序上收到以下错误。 我正在尝试使用Stripe设置订阅。 订阅属于业务和has_one计划。

在我看来,我在URL中传递了参数: http:// localhost:3000 / subscriptions / new?plan_id = 2&business_id = 1001

提交表单后,我收到以下错误,我的代码如下。 如果这是一个初学者问题,请原谅我。

NameError

订阅控制器

class SubscriptionsController  e flash[:error] = e.message render :new end private def stripe_params params.permit :stripeEmail, :stripeToken end # Use callbacks to share common setup or constraints between actions. def set_subscription @subscription = Subscription.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def subscription_params params.require(:subscription).permit(:plan_id, :business_id) end end 

订阅模型

 class Subscription < ActiveRecord::Base belongs_to :business has_one :plan def process_payment customer = Stripe::Customer.create email: email, card: card_token Stripe::Charge.create customer: customer.id, amount: plan.price * 100, description: plan.name, currency: 'usd' end end 

订阅视图(new.html.erb)

   

prohibited this subscription from being saved:

<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="" data-image="/img/documentation/checkout/marketplace.png" data-name="Business Name" data-description="" data-amount="">

计划模型

 class Plan < ActiveRecord::Base belongs_to :subscription end 

调用render只加载一个动作的视图,它不会运行动作背后的方法中的任何逻辑,这就是为什么在你从create动作render :new时没有@plan可用的原因。

我发现问题在于我的计划和订阅之间的关联。 我有计划belongs_to订阅,当我应该有它反过来。

 class Subscription < ActiveRecord::Base belongs_to :business belongs_to :plan ...