Skip to content

Instantly share code, notes, and snippets.

@rjohnson4444
Last active October 27, 2015 17:44
Show Gist options
  • Save rjohnson4444/9aa6ce16f2669c09c788 to your computer and use it in GitHub Desktop.
Save rjohnson4444/9aa6ce16f2669c09c788 to your computer and use it in GitHub Desktop.
Rails
Rails
-----
Table relationships
-------------------
- A one - to - one relationship is a city to a professional basketball team. One basketball team has only one city.
- A one - to - many relationship is a person and their shoes collection. One person owns many shoes, but each shoe only has one owner
- A many - to - many relationship is a classes to students relationship.
Test development is used specifically for testing you code. It is used when the test are being ran.
Development enviornment is used when the code is in development. when the server is being ran, it uses the development enviornment.
(checkout 'faker' gem for fake data)
Production enviornment is used when the app is in production. When it is on the web.
You create a rails app from the command line with this in the terminal: `rails new appname --database=postgresql` or `rails new appname -d postgresql`
What type of files are created when you type in `rails g model`?
- A model file is created, along with a migration file with the specified columns (if you have put them in) along with some test files.
What's the difference between typing rails g model ... and rails g migration ...?
- The difference is rails g model gives you a model and a migrations at the same time, where rails g migration will give you a basic migration.
Imagine that the items table has a category called quantity. What command would you type if you wanted to get rid of the quantity attribute?
- $ rails g migration RemoveQuantityFromItems quantity:integer (Quantity being the column to remove and Items is the table to remove it from. From is the separator.
Imagine that you have a table students. What is the ActiveRecord query that would return all students with the first name of Richard?
- Student.where(first_name: "Richard") (where will return all instances that match the query.)
How would you update the student record with ID 4 to have a new phone number of "101-222-3333"?
- Student.find(4).update(phone_number: '101-222-3333') or
- Student.update(4, phone_number: '101-222-3333')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment