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 trialNikola Novakovic
4,171 PointsActiveRecords Relation Concept
Hey there peeps! :)
I am having a hard time grasping the active records relation. I understand that when you do for example:
@res_show = Customer.where(name: "Bob's Emporium")
It will return an active record relation, but I don't really see what is that relation about and what can I do with it? Is there a method that actually returns an actual customer's data where the name is "name_of_cust" ?
Thanks in advance!
1 Answer
Maciej Czuchnowski
36,441 PointsThis gives you an instance variable called @res_show which contains all the data pertaining to the customer "Bob's Emporium". From now on you can access all the attributes of that client using methods line this (let's assume that the customer has name, address, account number):
@res_show.address, @res_show.name, @res_show.account_number
Nikola Novakovic
4,171 PointsNikola Novakovic
4,171 PointsThanks a lot so it is actually a huge object :)