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 trialspalak
12,151 PointsWhere in the code are we creating the error messages?
I can follow along with the video and get the error messages to show up at the appropriate times. But I can't figure out where in the project code we've specified what the error messages is (even using a Cmd+Shift+F). For example, where do we say the message for having less than one character in content should be "Content is too short (minimum is 2 characters)"?
1 Answer
Pedro Garcia
8,426 PointsHi, The error messages can be edited/added in your model, as part of the validation. Lets say you have a User Model, and each user needs a username with a max length of 20 characters. So you validation should look something like this:
class User < ActiveRecord::Base
validates :username, presence: true,
length: { maximum: 20, message: "The username can have a maximum of 20 characters" }
end
Each validation can have a custom error message. Hope this helps. Sorry about my english.
Pete