模型命名空间中的错误

时间:2016-06-15 21:34:58

标签: ruby-on-rails forms

我将我的注册分解为一个整体注册模型,该模型具有多个模型名称空间(我相信这些是他们所称的)到单独的文件中。例如,

Signup.rb

class ContractorSignup < ActiveRecord::Base
# It has fields of first_name, last_name, email, phone_number, address
end

在注册文件夹中有这些模型

ContractorSignup::Personal < Signup
  validates_presence_of :first_name, :last_name, :email, :phone_number
end

在我使用主模型

的形式中
= form_for @contractor_signup, url: signup_step_path('email') do |form|
= form.label :first_name
= form.text_field :first_name
= form.submit "Next"

表单会回复正确的验证,但我无法弄清楚如何根据验证获取它捕获的错误。

接下来是针对Rails向导构建的复制此人的谈话。 http://www.codepainter.ca/2013/10/ultra-light-maintainable-wizards-in.html

如果我执行了@contractor_signup.errors.inspect,当我填写一张完全空白的表单时,我在@contractor_signup.errors.inspect中看不到任何消息。但是,我发现如果我提交的表单中包含姓名或姓氏的所有内容,我会收到错误消息first_name []

0 个答案:

没有答案