Reputation: 26919
So first I had this class:
class User < ActiveRecord::Base
attr_accessible :email, :name
end
and was able to create and save users in ruby sandbox.
Then I added validation like this:
validates(:name, presence: true)
saved my changes, went back to console, and said this:
>> user = User.new(name: "", email: "[email protected]")
>> user.save
It should return FALSE because name is blank. But it returned true. Why? Maybe I should restart the sandbox console?
Upvotes: 0
Views: 55
Reputation: 2266
Try doing:
reload!
in the console.
This will reload your models and should pick up the new validation. This makes it unnecessary to restart the console. I use this like a bajillion times a day. :D
Upvotes: 2
Reputation: 26919
Yes never mind. I restarted the sandbox console and now validation is working correctly.
Upvotes: 0