被称为nil的id,将错误地称为4-Rails 3

时间:2014-07-11 09:51:39

标签: ruby-on-rails ruby-on-rails-3

我目前正在运行rails 3,并在尝试使用stripe-gem订阅用户时不断收到此错误消息。

错误讯息:

调用id为nil,错误地为4 - 如果你真的想要id为nil,请使用object_id app / controllers / charges_controller.rb:55:在'create'

这是错误引用的引用行:

cur_employer = Employer.find_by_employer_id(current_employer.id)

以下是充电器控制器 Charges_controller.rb

def create
  card_token = params[:stripeToken]
  planid = params['planid']
  emply_nmbr = params['emply_nmbr']
  cur_employer = Employer.find_by_employer_id(current_employer.id)
      # Create and subscribe a Customer

 if emply_nmbr=="update_Card"
   already_subscribed = Subscription.find_by_employer_id(current_employer.id)
   customer = Stripe::Customer.retrieve(already_subscribed.customer_id)
   #customer.cards.retrieve(already_subscribed.card_id).delete()
  changed_card = customer.cards.create(:card => card_token)
    cust_crd = CustCard.new
    cust_crd.employer_id = current_employer.id
    cust_crd.cust_card_id = changed_card.id
    cust_crd.save
  #Subscription.where(:employer_id=> current_employer.id).update_all(:card_id=> changed_card.id)
   flash[:notice] = "Your Card Was Successfully Saved"
   redirect_to settings_path
 else
   customer = Stripe::Customer.create(
    :card => card_token,
    :plan => planid.to_s,
    :email => cur_employer.email,
    :description => 'App Subscription',
    :metadata => {'Name' => cur_employer.first_name << " "+cur_employer.last_name}
   )
  if customer.present?
    subs = Subscription.new
      subs.employer_id=current_employer.id
      subs.plan_id=planid
      subs.customer_id=customer.id
      subs.save

      cust_crd = CustCard.new
      cust_crd.employer_id = current_employer.id
      cust_crd.cust_card_id = customer.cards.data[0].id
      cust_crd.save

    Employer.where(:id=> current_employer.id).update_all(:paid_employees=> emply_nmbr)
     flash[:notice] = "You Have Subscribed Successfully"
     redirect_to settings_path
   end
  end
   rescue Stripe::CardError => e
   flash[:error] = e.message
  redirect_to charges_path
end

任何建议都会很棒!

0 个答案:

没有答案