Rails Flashcards

1
Q

Give a basic rundown of MVC

A

MVC = Model View Controller

It is to facilitate a Seperation of Concerns

Model -> data, model should have most complexities, keeping the controller simple

View -> UI, how it looks. should not manipulate data in any way, only display it.

Controller -> passing between Model and View. controller should be simple, model should have most complexities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

before running a site with a postgres database what do we need to do?

A

we need to start a postgres service, aka daemon. we can do this like so:

brew services start postgres

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how do we create a rails project?

and then what minimal steps do we take to get it running?

A

we run the command:

  • rails new MyFirstProject –database=postgresql*
  • rails server*

# creates some database files for your rails project to use (only needed when not using default database)
rake db:create

# to actually apply the changes do this:
rake db:migrate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what ports are reserved by international standards?

A

everything below 1024, but also there are reserved ports, check this list first:

https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does CRUD stand for?

A

Create

Read

Update

Destroy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how do we create a resource using a rail command?

A

rails generate scaffold HighScore name:string high_score:integer box_art_url:text

the object name must be singular, rails will pluralise it for database table names and relevent view and controller folder names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

when modifying tables, what files should be accessed directly (if conventient) and what should not be touched?

A

the schema.rb should be left alone and only modified by migrating migration file/s,

the migration file can be created throught rails commands and possibly filled in or modified manually.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what SQL rails commands can be used to return certain rows from a table?

A

SomeTable.first
SomeTable.last
SomeTable.all
SomeTable.all[n]
SomeTable.find(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how do we see what tables exist via postgres console and what columns it has?

A

[~/RailsProjects/MeetupClone]$ psql postgres
psql (11.5)
Type “help” for help.

postgres=#
postgres=# \c MeetupClone_development
You are now connected to database “MeetupClone_development” as user “lev”.
MeetupClone_development=#

MeetupClone_development=# \dt
List of relations
Schema | Name | Type | Owner
——–+———————-+——-+——-
public | ar_internal_metadata | table | lev
public | categories | table | lev
public | comments | table | lev
public | events | table | lev
public | groups | table | lev
public | schema_migrations | table | lev
public | users | table | lev
(7 rows)
MeetupClone_development=#
MeetupClone_development=# \d users
Table “public.users”
Column | Type | Collation | Nullable | Default
————–+—————————–+———–+———-+———————————–
id | bigint | | not null | nextval(‘users_id_seq’::regclass)
name | character varying | | not null |
email | text | | not null |
location | text | | |
about_me | text | | |
profile_pic | text | | |
sign_up_date | timestamp without time zone | | not null |
event_id | bigint | | |
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
group_id | bigint | | |
Indexes:
“users_pkey” PRIMARY KEY, btree (id)
“index_users_on_event_id” btree (event_id)
“index_users_on_group_id” btree (group_id)
Foreign-key constraints:
“fk_rails_cce00833b9” FOREIGN KEY (event_id) REFERENCES events(id)
“fk_rails_f40b3f4da6” FOREIGN KEY (group_id) REFERENCES groups(id)

MeetupClone_development=#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we use SQL rails commands to create, update and destroy table rows?

A
  • HighScore.create!(name:”Bubble Bobble”,high_score:420000)*
  • HighScore.find(1).update!(high_score: 320000, box_art_url: “https://someurladd.com”)*
  • HighScore.find(1).destroy*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how do we use a rails command to select with a conditional?

how do we do it with wild card strings?

A
  • HighScore.where(“high_score > ?”, 3000)*
  • HighScore.where(“high_score > ?”, value_variable)*
  • HighScore.where(“name like ‘This%’”)*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what are the two syntaxes we can use to generate a migration to add or remove a column from a table?

A

we can use snake case and camel case

  • rails generate migration add_validated_to_high_scores validated:boolean*
  • rails generate migration RemoveValidatedFromHighScores validated:boolean*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly