Skip to content

Instantly share code, notes, and snippets.

@cheezedigital
Created January 20, 2015 19:31
Show Gist options
  • Save cheezedigital/9395c42596c5b6315902 to your computer and use it in GitHub Desktop.
Save cheezedigital/9395c42596c5b6315902 to your computer and use it in GitHub Desktop.
objects
A class is used to create an object. It's like a blueprint
We have an Org class in the app
To create an Org object, we can do the following: Org.new
Or pull one from the database (orgs table): Org.find(ID)
The User class is also used to create objects
Under admin/users/index.html.haml we are looping through all the user objects in the database
users.each do |user|
...
end
Inside the block, the "user" variable contains one instance of an object
In the User class we have defined that the user belongs to an Org object
So we can call user.org to get the object
But we don't want to display the actual Org object to the user that is browsing the site because objects are only for us, developers, to use to create meaningful applications.
We want to display the name of the Org object because "name" is one of the attributes in the Org object.
Does that make sense?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment