Ruby on rails 使用简单表单和错误消息验证的确认

Ruby on rails 使用简单表单和错误消息验证的确认,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,使用Rails 3.2.12和simple_form 2.0.4 在我们的用户模型上,我们有: validates_confirmation_of :email, :on => :create, :message => "should match confirmation" validates_confirmation_of :password, :message => "Your password confirmation does not match the pas

使用Rails 3.2.12和simple_form 2.0.4

在我们的用户模型上,我们有:

  validates_confirmation_of :email, :on => :create, :message => "should match confirmation"
  validates_confirmation_of :password, :message => "Your password confirmation does not match the password entered"
不过,到目前为止还不错,如果这些字段中的任何一个出现确认错误(即它们不匹配),simple_form只会用错误类和错误消息标记常规字段。 我的客户希望匹配确认字段标记在相同的红色样式/错误类中

有没有一种方法可以在不进行重大重新设计的情况下使用简单的表单来实现这一点

这在我看来:(密码类似)

true,:label=>“验证电子邮件地址”,:input\u html=>{:rel=>“工具提示”,:title=>“请再次输入电子邮件地址以防止键入错误”}%>

谢谢

您可以在保存之前(或创建之前)执行此操作,并执行自定义验证和

before_create :email_validation

def email_validation
  if email validation stuff
    self.errors.add( :email, "error message")
    self.errors.add( :email_confirmation, "error message")
  end
end

这样,您也可以更好地控制显示何种错误消息。

不幸的是,这似乎对我不起作用;错误只是没有显示在视图上;可能是因为_确认字段不是“真实”字段。我将在视图中通过不使用简单表单和使用电子邮件确认中的错误来修复此问题
before_create :email_validation

def email_validation
  if email validation stuff
    self.errors.add( :email, "error message")
    self.errors.add( :email_confirmation, "error message")
  end
end