我想在将价格发送到表格/条带之前去掉价格中的小数点。我可以使用其他方法来执行此操作吗?
在我的 Product.rb 模型中,我有:
def monetize_amount
self.price.to_s.delete(".").to_f
end
Run Code Online (Sandbox Code Playgroud)
在 charge_controller 中我有:
def create
@product = Product.find(params[:id])
# Amount in cents
**@amount = @product.monetize_amount**
customer = Stripe::Customer.create(
:email => 'example@stripe.com',
:card => 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 charges_path
end
Run Code Online (Sandbox Code Playgroud) <%= form_for @article , :html => {:multipart=> true} do |f| %>
<% if @article.errors.any? %>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
Run Code Online (Sandbox Code Playgroud)
上面是我的表单的一个片段,我可以访问文章的验证,即:author, :title 的validates_presence 但是我无法访问我为nested_attributes 设置的验证,这些验证恰好是照片。关于如何显示错误消息的任何想法?