Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished HW #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.create({name: "Roquefort", color: "yellow", origin: "French", stink_level: 5})
```

- Charolais, a white french cheese with a stink level of 5
Expand All @@ -28,7 +28,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.create({name: "Charolais", color: "white", origin: "French", stink_level: 5})
```

- Hooligan, a yellow American cheese with a stink level of 3
Expand All @@ -37,15 +37,15 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.create({name: "Hooligan", color: "yellow", origin: "American", stink_level: 3})
```
- Teleme, a white american cheese with a stink level of 2
```sql
INSERT INTO cheeses (name, color, origin, stink_level) VALUES ('Teleme', 'white', 'American', 2);
```

```ruby
# your active record solution
Cheese.create({name: "Teleme", color: "white", origin: "American", stink_level: 2})
```
- And then we inserted a few more cheeses, but I think you get the point. Moving on!

Expand All @@ -59,7 +59,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.all
```

- Find all the French cheeses
Expand All @@ -69,7 +69,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({origin: 'French'}).select :id, :name
```
- Find all the English cheeses

Expand All @@ -78,7 +78,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({origin: 'English'}).select :id, :name
```
- Find all cheeses with a stink level of 2

Expand All @@ -87,7 +87,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({stink_level: 2}).select :id, :name
```
- Find all cheeses with a stink level of 10

Expand All @@ -96,7 +96,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({stink_level: 10}).select :id, :name
```
- Find all French cheeses with a stink level of 5

Expand All @@ -105,7 +105,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({stink_level: 5, origin: "French}).select :id, :name
```
- Find all Irish cheeses with a stink level of 6

Expand All @@ -114,7 +114,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({origin: "Irish", stink_level: 6}).select :id, :name
```
- Find all cheeses with a stink level of at least 4, but no greater than 8.

Expand All @@ -123,7 +123,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where("stink_level >=4 || stink_level <= 8").plunk(:name)
```
- Find all American and English cheeses.

Expand All @@ -132,7 +132,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where({origin: "American"}).or(Cheese.where({origin: "American"})).select :id, :name
```
- Find all cheeses that are not from France.

Expand All @@ -141,7 +141,7 @@ For all solutions, pretend that you have a model called `Cheese`.
```

```ruby
# your active record solution
Cheese.where.not({origin: "American"}).select :id, :name
```


Expand All @@ -156,7 +156,7 @@ The cheese game is changing constantly. Let's update our cheeses.
```

```ruby
# your active record solution
Cheese.where(name: Roquefort).update_attribute(:stink_level, 3)
```
- Change the color of Teleme to "mauve"

Expand All @@ -165,7 +165,7 @@ The cheese game is changing constantly. Let's update our cheeses.
```

```ruby
# your active record solution
Cheese.where(name: Teleme).update_attribute(:color, mauve)
```
- Delete the Hooligan cheese

Expand All @@ -174,7 +174,7 @@ The cheese game is changing constantly. Let's update our cheeses.
```

```ruby
# your active record solution
Cheese.where({name: "Hooligan"}).destroy
```
- Change the stink level of Stichelton to be 7

Expand All @@ -183,7 +183,7 @@ The cheese game is changing constantly. Let's update our cheeses.
```

```ruby
# your active record solution
Cheese.where(name: Stichelton).update_attribute(:stink_level, 7)
```
- Add the cheese "Monterey Jack", an American cheese with a stink level of 0

Expand All @@ -192,7 +192,7 @@ The cheese game is changing constantly. Let's update our cheeses.
```

```ruby
# your active record solution
Cheese.create({name: "Monterey Jack", color: "white", origin: "American", stink_level: 0})
```
- Delete Durrus

Expand All @@ -201,53 +201,53 @@ The cheese game is changing constantly. Let's update our cheeses.
```

```ruby
# your active record solution
Cheese.where({name: "Durrus"}).destroy
```

## Part 2: Review Today's Lesson:
Review the `README.md` file from today's lesson [here](https://github.com/WDI-HoneyBadger/w10d03-intro-to-rails) then answer the following questions:

- In express we built our routes inside of our controller, where do you put routes in a rails app?
```
# your answer here
on its own entity
```
- Should a rails model be lower-case and plural, upper-case and plural, lower-case and singular, or upper-case and singular?
```
# your answer here
upper-case and singular
```
- What kind of files belong in the `assets` directory?
```
# your answer here
JS, CSS
```
- What does the command `rails db:drop` do?
```
# your answer here
Drop the app's database
```
- What does the command `rails c` do?
```
# your answer here
Run the console
```
- What is an ORM? What does it stand for?
```
# your answer here
Object-relational mapping (tool) is a programming technique for converting data between incompatible type systems using object-oriented programming languages.
```
- What does a migration file do?
```
# your answer here
Migrations are where we are going to define what our tables will look like.
```
- How do you run your migration files?
```
# your answer here
rails db:migrate
```
- How do you start a rails server?
```
# your answer here
rails s
```
- What is the command to start a new rails API called "reasons_why_ghadeer_rules"?
```
# your answer here
rails reasons_why_ghadeer_rules --api -G --database=postgresql
```
- What is an API?
```
# your answer here
API is just a website that has no view, it only displays data.
```