【发布时间】:2015-03-05 04:57:42
【问题描述】:
我正在学习 Michael Hartl 的 Ruby on Rails 教程,并且一直在验证。这是我在控制台中的测试:
root@sample_app# rails console
Loading development environment (Rails 4.2.0)
user = User.new(name: "", email: "mhartl@example.com")
#=> #<User id: nil, name: "", email: "mhartl@example.com", created_at: nil, updated_at: nil>
user.valid?
#=> true
user = User.new(name: "Example User", email: "mhartl@example.com")
#=> #<User id: nil, name: "Example User", email: "mhartl@example.com", created_at: nil, updated_at: nil>
user.valid?
#=> true
无论名称是什么,user.valid? 总是返回 true。有人知道为什么吗?
【问题讨论】:
-
您能否提供您对
name字段的验证?
标签: ruby-on-rails ruby ruby-on-rails-3 validation