0
我正在嘗試使用stripe
創建一個註冊表單以支付事件費用。但是我在提交表單時遇到了錯誤。Rails沒有爲條紋簽出註冊設置方法錯誤
這是我得到的錯誤:
NoMethodError in Users::RegistrationsController#create
undefined method `to_sym' for nil:NilClass
Extracted source (around line #7):
def create
super do |resource|
if params[:objective]
resource.objective_id = params[:objective]
if resource.objective_id == 1
這裏是我的控制器:
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: :null_session
before_action :configure_permitted_parameters, if: :devise_controller?
# whitelist the following form fields so that we can process them
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |r| r.permit(:stripe_card_token, :password, :password_confirmation, :email, :first_name, :last_name, :company, :street, :city, :state, :zip, :phone, :roadshowcity, :comments) }
end
end
我註冊記憶控制器(這裏我目前得到的錯誤):
class Users::RegistrationsController < Devise::RegistrationsController
# Extend default devise gem behavior so that users
# signing up with the registration form (roadshow)
# save with a special stripe subscription function.
# Otherwise Devise signs up user as usual.
def create
super do |resource| **<====Error here(NoMethodError undefined method `to_sym' for nilclass)**
if params[:objective]
resource.objective_id = params[:objective]
if resource.objective_id == 1
resource.save_with_registration
else
resource.save
end
end
end
end
end
我的模特:
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 :regis
attr_accessor :stripe_card_token, :id
# If user passes validations (email, pass, etc.),
# Call stripe and tell stripe to set up a subscription
def save_with_registration
if valid?
@product_price = Objective.find(objective_id)
customer = Stripe::Customer.create(email: email, card: stripe_card_token, description: stripe_card_token.to_s)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => 900,
:currency => "usd",
:description => "Registration"
)
self.stripe_customer_token = customer.id
save! <----- Error here(no method!)
end
end
end