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! While you're at it, check out some resources Treehouse students have shared here.
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

Shawn Wilson
iOS Development Techdegree Student 7,049 PointsCustom Validation challenge..
so the challenge is to build a custom validation to ensure no last_name is evil.. this is my code and it is prettywell exact to the video without the validations..
My CODE:
class Contact < ActiveRecord::Base
validate: name_is_not_evil
def name_is_not_evil
if last_name.include?("Evil")
errors.add(:last_name, "is Evil")
end
end
end
all i get it Bummer.. Try Again this is getting ridiculous. thanks for the help in advance.
2 Answers

Maciej Czuchnowski
36,441 PointsYou are very close, just move the colon from validate
to :name_is_not_evil
validate :name_is_not_evil
This should help you: http://guides.rubyonrails.org/active_record_validations.html#custom-methods

Salman Akram
Courses Plus Student 40,065 PointsHi Shawn,
I found minor semi-colon mistake right there under validate line.
validate: name_is_not_evil
Here's better example to meet the challenge question without extra codes, see below
class Contact < ActiveRecord::Base
validate :name_has_no_evil
def name_has_no_evil
if last_name.include?("Evil")
errors.add(:last_name, "Can not be Evil")
end
end
end
Hope that helps :)
Shawn Wilson
iOS Development Techdegree Student 7,049 PointsShawn Wilson
iOS Development Techdegree Student 7,049 Pointsi was tired an forgot that i have this forum question open aswell on this topic
https://teamtreehouse.com/forum/build-a-custom-validator-that-ensures-that-no-contact-s-lastname-is-evil-issue-with-challenge