当我尝试运行代码时,我收到上面的错误。 这发生在我的条带支付表格上: 第1步:用户选择计划 第2步:用户确认当前计划 第3步:用户为此计划付费 错误来自第三步。
以下是日志:
Started POST "/subscriptions" for 127.0.0.1 at 2015-07-27 08:03:57 +0200
Processing by SubscriptionsController#new as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"8oQZ2GBhAcAmrDtfbH0SEmbjfzfO2+nfpUtpIySUyTQ=", "subscription"=>{"company"=>"", "adress"=>"", "city"=>"", "country"=>"", "postal_code"=>"", "phone"=>"", "plan_id"=>"52", "stripe_card_token"=>""}, "commit"=>"Terminer la commande"}
Completed 404 Not Found in 1ms
ActiveRecord::RecordNotFound (Couldn't find Plan without an ID):
app/controllers/subscriptions_controller.rb:11:in `new'
这是subscription_controller.rb:
require "stripe"
skip_before_filter :verify_authenticity_token
skip_before_action :set_plan, only: [:new, :create]
def new
@titre = "Terminer la commande"
plan = Plan.find(params[:plan_id])
@subscription = plan.subscriptions.build(:plan_id => params[:plan])
end
def create
@subscription = Subscription.new(params[:subscription])
if @subscription.save_with_payment
flash[:success] = 'Congrats'
redirect_to nosformations_path
else
flash[:error] = "Error"
redirect_to root_url
end
end
private
def set_plan
@plan = Plan.find(params[:plan_id])
end
这是模型Subscription.rb:
belongs_to :plan
belongs_to :user
validates_presence_of :plan_id
validates_presence_of :email
attr_accessible :name, :price, :old_price, :also, :type_of, :interval, :description, :plan_id, :company, :adress, :city, :country, :postal_code, :phone, :stripe_card_token, :coupon
attr_accessor :stripe_card_token
def save_with_payment
if valid?
customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token, email: email)
self.stripe_customer_token = customer.id
save!
end
rescue Stripe::InvalidRequestError => e
logger.error "Erreur Stripe lors de la création du profil client : #{e.message}"
errors.add :base, "Le paiement a échoué. Merci de vérifier les paramètres de paiement."
false
end
我正在寻找几个小时没有成功的回复...... 任何的想法 ?
答案 0 :(得分:0)
在new
subscriptions_controller
行动中更改此行:
plan = Plan.find(params[:plan_id])
为:
plan = Plan.find(params[:subscription][:plan_id])
与你的参数一样,plan_id
内有subscription
:
Parameters: {"subscription"=>{"company"=>"", "adress"=>"", "city"=>"", "country"=>"", "postal_code"=>"", "phone"=>"", "plan_id"=>"52", "stripe_card_token"=>""}}
希望这有帮助。