Last active
May 1, 2019 18:54
-
-
Save Alacrity01/b38cb91c68ae7eddcca0a1545e5dc4c1 to your computer and use it in GitHub Desktop.
Week 2, Day 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. WEB REQUEST WINDOW ORDER | |
2. API ROUTE DESKTOP CHROME SUBLIME TERMINAL SLACK | |
3. API CONTROLLER (gets data from MODEL) <-- subject for today | |
4. JSON VIEW | |
5. WEB RESPONSE | |
All Rails apps come pre-git init | |
rails new cookbook_app | |
cd cookbook_app | |
rake db:create | |
rails generate controller api/recipes <--recipes must be plural because all controller names must be plural | |
subl . | |
rails generate model Recipe title:string chef:string ingredients:string directions: string image_url:string prep_time:integer | |
^ Name of model should be upper camelcase and singular. | |
Everything following the name are attributes of the model. | |
You cannot change the migration file after migrate step | |
rake db:migrate Rails has prebuilt reader and writer methods. | |
rails console <-- IRB with the entire rails framework loaded into it | |
CRUD method: create, read, update, destroy | |
recipe = Recipe.new(title: "Raw Egg", chef: "Josh", ingredients: "live chicken, rubber gloves", directions: "put on gloves, squeeze chicken lightly", prep_time: 5) | |
recipe.save | |
recipe.title = "Egg" <-- Will overwrite attribute "title"; you must still save though. | |
Recipe.all <-- will show all objects created within that model (which is class plus the database table) | |
Recipe.find_by(title: "Hand Sandwich") <--Usually you wil search by id | |
Recipe.find(2) <-- same as Recipe.find_by(id: 2) find_by(id: ) is so common that it has a shortcut. | |
recipe = Recipe.find(2) | |
recipe = _ <--underscore will give you the return value of the line above, so this would be the same | |
recipe.destroy <--will destroy the current object you are working on | |
rails server | |
command-control up/down moves the current line up or down in sublime | |
Separation of Concerns: Modular Programming | |
Separation of concerns is writing specific types of code in specific files, each of which has its own purpose. The value is simplifying development and maintenance of computer programs. Enables you to make changes to individual sections independently without having to understand the other sections of the full program. | |
MVC design is the specific convention of Rails (Model, View, Controller) | |
Model = stored data | |
defines how we interact with stored information | |
ORM - object relational mapping software -- translates Rails into SQL commands to interact with database. | |
View = interface | |
defines how the user sees and sends information to our application | |
In rails, usually json or html. | |
Controller = logic flow | |
the leader, analyzing and giving commands | |
Combines pieces together. | |
Usually involves if statements, filters, or CRUD operations. | |
SQL/relational database | |
• means it has columns and rows | |
NoSQL/non-relational database | |
• means does not have columns and rows | |
In a database: | |
rows are instances <-- these are interchangable when using databases | |
columns are attributes | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment