现在,当submit.html.erb加载时,我收到此错误消息:".pagerlink:last-child a"
。
我想了解如何改进我的控制器。目标是在加载提交页面时没有错误消息。但只有当实际用户提交虚假信息时才会这样做。
TextField searchInput = new TextField();
searchInput.setId("textField");
searchInput.setPromptText("Search");
这是submit.html.erb
Cannot charge a customer that has no active card
如果我可以提供更多背景信息,请告知。
答案 0 :(得分:1)
重构为此,现在可行:
class SubmissionsController < ApplicationController
include Wicked::Wizard
steps :name, :details, :comments, :submit, :thankyou
def show
get_company
set_package
render_wizard
end
def update
case step
when :thankyou
get_company
render_wizard @company
when :submit
get_company
set_package
if request.put?
create_customer
do_payment
render_wizard @company
end
else
get_company
params[:company][:status] = 'active' if step == steps.last
@company.update_attributes(company_params)
render_wizard @company
end
end
def get_company
@company = Company.find(params[:company_id])
end
def create_customer
@customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
end
def set_package
@amount = 50
@amount_in_decimals = @amount / 100.00
@description = "Premium Package"
end
def do_payment
Stripe::Charge.create(
:customer => @customer.id,
:amount => @amount,
:description => @description,
:currency => "eur"
)
rescue Stripe::CardError => e
flash[:error] = e.message
end
和视图
<label class="amount">
<span>Amount: <%= number_to_currency(@amount_in_decimals, :precision => 2, :locale => :nl) %></span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-name="RailsApp!"
data-description='<%= @description %>'
data-amount=<%= @amount %>
data-locale="auto"
data-currency="eur"></script>
<% end %>