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: "mhartl@example.com")
>> user.save
It should return FALSE because name is blank. But it returned true. Why?
Maybe I should restart the sandbox console?
Try doing:
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. 😀