Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Sebastian Bachmann7,046 Points
[Done - Solution included] Build a custom validator that ensures that no Contact’s last_name is Evil.
i am stuck here again. And this time i don't even have a clue where to start. This is a bit over my head. So, if someone can push me in the right direction would be awesome.
Check out the custom validators section of the Rails documentation to get started. In general you're going to want to define a custom validator that will inspect your last_name field and make sure it's not included in a list of unacceptable names.
Jason Shultz4,840 Points
I don't understand why this didn't work:
class GoodnessValidator < ActiveModel::Validator def validate(record) if record.lastt_name == "Evil" record.errors[:base] << "This person is evil" end end end class Contact < ActiveRecord::Base validates_with GoodnessValidator end