Ruby on rails Rails条纹-您必须提供有效的卡
在我的应用程序中,我使用“条纹”宝石来设置付款。一切都进行得很顺利,但每当我提交付款时,就会出现错误“您必须提供有效的卡”。 下面是我的代码 广告控制器Ruby on rails Rails条纹-您必须提供有效的卡,ruby-on-rails,ruby-on-rails-4,coffeescript,credit-card,stripe-payments,Ruby On Rails,Ruby On Rails 4,Coffeescript,Credit Card,Stripe Payments,在我的应用程序中,我使用“条纹”宝石来设置付款。一切都进行得很顺利,但每当我提交付款时,就会出现错误“您必须提供有效的卡”。 下面是我的代码 广告控制器 class AdsController < ApplicationController before_action :set_ad, only: [:show, :edit, :update, :destroy] # GET /ads # GET /ads.json def index @ads = Ad.or
class AdsController < ApplicationController
before_action :set_ad, only: [:show, :edit, :update, :destroy]
# GET /ads
# GET /ads.json
def index
@ads = Ad.order('created_at DESC').search(params[:search])
@ads_small = Ad.where(:size => "small").order('created_at DESC')
@ads_medium = Ad.where(:size => "medium").order('created_at DESC')
@ads_featured = Ad.where(:size => "featured").order('created_at DESC')
end
def myads
@ads_mine = Ad.where(:user_id => current_user.id )
end
# GET /ads/1
# GET /ads/1.json
def show
end
# GET /ads/new
def new
@ad = Ad.new
end
# GET /ads/1/edit
def edit
end
# POST /ads
# POST /ads.json
def create
@ad = Ad.new(ad_params)
@ad.user_id = current_user.id
respond_to do |format|
if @ad.save_with_payment
format.html { redirect_to @ad, notice: 'Ad was successfully created.' }
format.json { render action: 'show', status: :created, location: @ad }
else
format.html { render action: 'new' }
format.json { render json: @ad.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /ads/1
# PATCH/PUT /ads/1.json
def update
respond_to do |format|
if @ad.update(ad_params)
format.html { redirect_to @ad, notice: 'Ad was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @ad.errors, status: :unprocessable_entity }
end
end
end
# DELETE /ads/1
# DELETE /ads/1.json
def destroy
@ad.destroy
respond_to do |format|
format.html { redirect_to ads_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_ad
@ad = Ad.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def ad_params
params.require(:ad).permit(:title, :url, :preview, :location, :size, :info, :search)
end
end
任何帮助都将不胜感激。:) 在您的
Ad
型号中,您有:
attr_accessor :stripe_card_token
然后使用随付随存中的令牌
:
customer = Stripe::Customer.create(..., card: stripe_card_token)
self.stripe_customer_token = customer.id
到目前为止还不错。但是,当您创建ad
时,您可以使用ad\u params
在控制器中过滤params
:
def ad_params
params.require(:ad).permit(:title, :url, :preview, :location, :size, :info, :search)
end
我在允许列表中的任何地方都没有看到:stripe\u card\u token
。您的HTML中的#ad#stripe_card_token
可能如下所示:
<input type="hidden" name="ad[stripe_card_token]">
因此,您应该能够将
:stripe_card_token
添加到ad_params
中的允许列表中,并开始工作。是的,它们只是复制粘贴错误,但我已将它们整理出来:)这是实时还是测试?在测试中…我认为唯一有效的方法是把4242作为卡号…对不起,我没有注意到这个答案,我最终还是弄明白了,但我还是会投票支持你的答案。
def ad_params
params.require(:ad).permit(:title, :url, :preview, :location, :size, :info, :search)
end
<input type="hidden" name="ad[stripe_card_token]">