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

Ruby ActiveRecord Basics Validation Using Validations

Randy Shelford
Randy Shelford
4,836 Points

It looks like he adds validation for the TimeEntry model, then tests it against its parent, the AccountEntry model.

This is at about the 10:12 mark in the video.

When he tests it in the console, with e.valid? it returns false, but I'm pretty sure that is only because the account_id is nil (from the previous validation he entered) and not because of the TimeEntry validation, because that shouldn't affect the AccountEntry model at all,

My question is, am I correct in this assessment, or am I missing something?

2 Answers

I get the e.valid? saying true for the AccountEntry but the validation works when I create TimeEntry.new(:time => 100).

I'm confused! But at least I think the validation works, as long as the addition of time is done within TimeEntry, not AccountEntry.

Steve.

Kyle Robertson
Kyle Robertson
31,600 Points

Yeah, if you call e = AccountEntry.new(:time => 100) then check e.errors, you'll see the message returned for AccountEntry, not TimeEntry

@messages={:account_id=>["can't be blank"]}