通過我的回報率的網站提交的電子郵件和密碼後,我提示一個錯誤消息,指出當我嘗試在我的網站上註冊一個帳號,我有錯誤返回「計劃必須存在」
「計劃不存在。」
用戶類
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :plan
attr_accessor :stripe_card_token
def save_with_subscription
if valid?
customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
self.stripe_customer_token = customer.id
save!
end
end
end
聯繫人控制器
class ContactsController < ApplicationController
# Get request to /contact-us
# show new contact form
def new
@contact = Contact.new
end
# Post request /contacts
def create
# Mass assignment of form fields into Contact object
@contact = Contact.new(contact_params)
# save the Contact object to the database
if @contact.save
# Store form fields via parameters. into variables
name = params[:contact][:name]
email = params[:contact][:email]
body = params[:contact][:comments]
# Plug variables into Contact Mailer email method and send email
ContactMailer.contact_email(name, email, body).deliver
# Store success message in flash hash
# redirect to the new action
flash[:success] = "Message sent."
redirect_to new_contact_path
else
# If Contact object doesnt save,
# store errors in a flash hash
# and redirect to the new action
flash[:danger] = @contact.errors.full_messages.join(", ")
redirect_to new_contact_path
end
end
private
# To collect data from form, we need to use
# strong parameters and whitelist the form fields
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
個
註冊記憶
class Users::RegistrationsController < Devise::RegistrationsController
def create
super do |resource|
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 2
resource.save_with_subscription
else
resource.save
end
end
end
end
end
基本形式
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, class: 'form-control' %>
</div>
<div class="field form-group">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %>
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>
<div class="field form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
</div>
<div class="actions form-group">
<%= f.submit "Sign up", class: 'btn btn-success' %>
</div>
<% end %>
我不確定我可能需要添加什麼。我正在做有趣的課程。在使用條紋插件添加計劃ID之前,我能夠創建一個帳戶。我試着在一個解決方案的stackoverflow上搜索,但沒有發現。我很善良,在我完成這部分之前無法繼續。我的網站的高級訂閱部分也無法正常工作,但這樣做後可以修復。
如果有人對我能做些什麼來解決這個問題有任何建議,那麼這個問題會非常令人滿意,或者我將添加什麼文件才能達到您的答案。
謝謝。
plan.rb
class Plan < ActiveRecord::Base
has_many :users
end
我可能在這裏弄錯了,但我不確定最新版本的Stripe API可以讓你創建一個像這樣的計劃的客戶。他們期望創建訂閱並將客戶分配到該訂閱。 – ellitt