令牌未定义RUBY

时间:2016-05-05 09:51:10

标签: ruby-on-rails token stripe-payments

我已经处理了这个错误2天,做了一些修改后得到了一些其他错误,我纠正了,现在我又回到了这个请帮忙吗?

我想这些都是帮助你们解决问题的课程

Error user.js

   class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  belongs_to :plan
  has_one :profile
  attr_accessor :stripe_card_token

  def save_with_payment
    if valid?
      customer = Stripe::Customer.create(description: email, plan: plan_id, source: stripe_card_token)
      self.stripe_customer_token = customer.id
      save!
    end
  end
end

    class Users::RegistrationsController < Devise::RegistrationsController
  before_filter :select_plan, only: :new

  def create
    super do |resource|
      if params[:plan]
        resource.plan_id = params[:plan]
        if resource.plan_id == 2
          resource.save_with_payment
        else
          resource.save
        end
      end
    end
  end
 end


    class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :configure_permitted_parameters, if: :devise_controller?
  protected
    def configure_permitted_parameters
      devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :stripe_card_token, :email, :password, :password_confirmation) }
    end
end

1 个答案:

答案 0 :(得分:0)

Javascript file error您在哪里为用户设置stripe_card_token属性?它似乎没有设置在您的代码中的任何位置。

另外,请确保您将控制器参数列入白名单,并在您的参数中发送stripe_card_token

Users::RegistrationsController

before_filter :configure_sign_up_params, only: :create

def configure_sign_up_params
    devise_parameter_sanitizer.for(:sign_up) << [:stripe_card_token, :any_other_params_you need_saved]
  end