Question

I have this application which I'm messing around with. (didn't create it, but trying fiddle with it and learn more about querying it, etc).

So, it has a lot of tables.

So, when I go into console, and ask User.first, I get the first one obviously.

(btw, you capitalize it and make it singular, right? even though tables are lower-case and plural?)

But when I ask for, say Tutor_appointment.first, this is what I get

`NameError: uninitialized constant Tutor_appointment from (pry):25:in `<main>'

Or even say, User_profile.first, again same thing:

`NameError: uninitialized constant User_Profile from (pry):30:in `<main>'

Why do I get these errors?

These are actual tables, and they do have data in it.

Am I querying the camelcase tables wrongly?

Was it helpful?

Solution

Yes you're correct that database table names are generally lowercase and plural. The model class names that represent those tables are uppercase and singular and no underscores.

In the console when you're doing User.first, it's not going directly to the database, it's actually calling .first() on the User model, a class. So you need to find the models for the tutor_appointments and user_profiles tables, and they're likely called TutorAppointment and UserProfile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top