如何将该脚本以红宝石形式合并,以便条纹收费如果不创建贴子,则不会通过。红宝石,条纹和javascript
现在,如果我删除验证帖子发布如果收费经过,如果收费不通过帖子不张贴。
只要我添加验证和缺少的东西,通过点击付费时,收费是正确的,验证停止在数据库中保存后,但收费仍然通过。
娶妻
<%= form_for @post do |f| %>
<div>
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div>
<%= f.label :phone_number %>
<%= f.text_field :phone_number %>
</div>
<div>
<%= f.label :post %>
<%= f.text_area :post %>
</div>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="Good Luck"
data-amount="500"
data-locale="auto"></script>
<% end %>
柱控制器
class PostsController < ApplicationController
before_action :authenticate_admin!, only: [:index]
def index
@posts = Post.all
end
def new
@post = Post.new
end
def show
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post, notice: 'Your post was create'
else
render :new
end
# Amount in cents
@amount = 150
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
private
def post_params
params.require(:post).permit(:name, :email, :phone_number, :post)
end
end
桩模型
validates :name, :phone_number, :post, presence: true
validates :email,
presence: true,
format: { with: /\b[A-Z0-9._%a-z\-][email protected](?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/}
的'高清create'是,或多或少,一个隐含的'begin',所以你并不需要一个明确的'begin'如果你想'救援'适用于整个方法。 –
是的,这件事情没有奏效。你有其他建议吗? –
如果验证未通过,我不希望打开条带电荷弹出窗口。 –