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
Steven Rodriguez
5,643 PointsRails 4 Validations
So I'm watching the "Build a todo list in Rails 4" videos and I noticed that in order to validate length and presence of text/string in a form, Jason does this:
validates :title, presence: true
validates :title, length: { minimum: 3 }
validates :description, presence: true
validates :description, length: { minimum: 5 }
Instead of doing this:
validates :title, presence: true, length: { minimum: 3 }
validates :description, presence: true, length: { minimum: 5 }
I did it the 2nd way because it condenses it down to 2 lines of code as opposed to 4 lines of code. Is the first way good practice and should be followed or was it done like that just to make the example easier to see/understand?
1 Answer

Lauralee Flores
1,501 PointsGreat question Steven. I wonder if he did it for readability. I have always done it the way you're doing it (all on one line).
I'm curious now though his reasoning - if it was because of best practices or personal preference.
Steven Rodriguez
5,643 PointsSteven Rodriguez
5,643 PointsGoing further into other videos, I noticed he did a validation the same way I did. I still don't know which would be considered best practice, but either way at least I know he does it too :P