Ruby on rails 不能';在订阅控制器中找不到没有ID的计划
当我试图运行代码时,我得到了上面的错误。 这发生在我的条纹付款表上: 步骤1:用户选择一个计划 第二步:用户确认当前计划 步骤3:用户为此计划付费 错误出现在第三步 以下是日志:Ruby on rails 不能';在订阅控制器中找不到没有ID的计划,ruby-on-rails,ruby,Ruby On Rails,Ruby,当我试图运行代码时,我得到了上面的错误。 这发生在我的条纹付款表上: 步骤1:用户选择一个计划 第二步:用户确认当前计划 步骤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"=>"✓","authen
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'
以下是订阅_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
我正在寻找一个响应几个小时没有成功。。。
有什么想法吗 在您的
new
操作中的subscriptions\u controller
更改此行:
plan = Plan.find(params[:plan_id])
致:
与您的参数一样,您在订阅中有计划id
:
Parameters: {"subscription"=>{"company"=>"", "adress"=>"", "city"=>"", "country"=>"", "postal_code"=>"", "phone"=>"", "plan_id"=>"52", "stripe_card_token"=>""}}
希望这能有所帮助。尝试plan=plan.find(params[:subscription][:plan\u id])
而不是plan=plan.find(params[:plan\u id])
为什么新操作的动词是POST?“这不应该是创造动作吗?”dreamingblackcat是的,你说得对,它会的
Parameters: {"subscription"=>{"company"=>"", "adress"=>"", "city"=>"", "country"=>"", "postal_code"=>"", "phone"=>"", "plan_id"=>"52", "stripe_card_token"=>""}}