【问题标题】:Override validation message on spree credit card create during checkout在结帐期间创建的大礼包信用卡上覆盖验证消息
【发布时间】:2014-11-11 20:03:41
【问题描述】:

我正在尝试在 Spree 1.3 的 checkout/payment 期间覆盖以下错误消息

当用户忘记输入信用卡号、月份或 cvv 时,会显示此消息:

Payments source is invalid

module Spree
  class CreditCard < ActiveRecord::Base

    validates :month, :year, :numericality => { :only_integer => true }
    validates :number, :presence => true, :unless => :has_payment_profile?, :on => :create
    validates :verification_value, :presence => true, :unless => :has_payment_profile?, :on => :create

上面创建的验证正在发送这个错误消息,我想用更有用的东西覆盖它,比如:Please check the credit card information entered.

有谁知道在验证未通过时如何覆盖创建自定义错误消息。

提前谢谢你。

【问题讨论】:

    标签: ruby ruby-on-rails-3 spree


    【解决方案1】:

    试试这个

    module Spree
      class CreditCard < ActiveRecord::Base
    
      validates :verification_value, :presence => true, :unless => :has_payment_profile?, :on => :create,
      message: "%{value} is reserved." }
    end
    

    【讨论】:

    • 我最终在视图中覆盖了它
    猜你喜欢
    • 2014-08-01
    • 2012-12-27
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 2012-08-28
    • 2014-03-21
    • 1970-01-01
    • 2020-01-17
    相关资源
    最近更新 更多