0
我想添加验证到我的用户模型,但没有失败,数据不断传递。对于名字,我没有条目。请看下图:验证通过时,它应该失败 - 迈克尔哈特尔的RoR,6.2.2
1.9.3p286 :012 > user = User.new(name: "", email: "[email protected]")
=> #<User id: nil, name: "", email: "[email protected]", created_at: nil, updated_at: nil>
1.9.3p286 :013 > user.save
(0.1ms) SAVEPOINT active_record_1
SQL (1.5ms) INSERT INTO "users" ("created_at", "email", "name", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sun, 23 Dec 2012 18:52:00 UTC +00:00], ["email", "[email protected]"], ["name", ""], ["updated_at", Sun, 23 Dec 2012 18:52:00 UTC +00:00]]
(0.1ms) RELEASE SAVEPOINT active_record_1
=> true
这是我在app/models/user.rb
:
class User < ActiveRecord::Base
attr_accessible(:name, :email)
validates(:name, presence: true)
end
这应该失败。有什么建议么?谢谢!
不知道我做了什么。但它开始正常工作。谢谢! – LearningHowToCode