Chapter 6 Flashcards

You may prefer our related Brainscape-certified flashcards:
0
Q

What is the syntax to generate a model?

A

$rails generate model singularModelName attribute1:datatype attribute2:datatype

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

What is the default Rails library used for interacting with a database?

A

ActiveRecord

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

What is the difference between model names and controller names?

A

Controller names are plural

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

What is a migration?

A

A way to alter the structure of a database incrementally, so that models can adapt to changing requirements

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

How do we run the scripts to ‘migrate up’ our database?

A

$bundle exec rake db:migrate

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

What is the name of the column Rails generates in the database for each row?

A

ID; an integer

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

How do we ‘migrate down’ and undo a database migration?

A

$bundle exec rake db:rollback

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

What is the command to start the rails console in a way that any changes to the database are rolled back upon exiting the console?

A

$rails console –sandbox

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

What is the command to insert a new object into the database?

A

newObject.save

This method returns a boolean of whether or not it was successful

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

T/F: an model object created with #new is not saved to the database.

A

T; It is added to the database with #save

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

What is special about the model method #create

A

It makes a new instance of the model and updates the database accordingly, and returns the object

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

What is the inverse of #create

A

destroy

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

What are the Active Record methods to find users?

A

find, which takes an id integer

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

If we have made changes to an object but have not saved these changes to a database and want to roll back to the values in the database, what method is used?

A

instance.reload.attributeName

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

What is a method to update multiple attributes?

A

update_attributes(options hash)

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

What is an Active Record validation?

A

It ensures that any addition/modification to the database conforms to certain rules

17
Q

What is the syntax of the ‘validates’ function?

A

validates(attribute, options hash)

18
Q

How can we see the errors produced when an object fails a validation?

A

objectName.errors.full_messages

19
Q

What is the method to see if an object passes all validations?

A

valid?

20
Q

Explain the following regex:

/\A[\w+-.]+@[a-z\d-.]+.[a-z]+\z/i

A

From the start of the string (\A), find at least one character, plus, hyphen, or dot ([\w+-.]), followed by (+) the literal @ sign, followed by at least one letter, digit, hyphen, or dot ([a-z\d-.]), followed by a literal dot, followed by at least one letter ([a-z]), followed by an end of the string (\z)

21
Q

T/F: The ‘uniqueness’ option for the validates function looks in the database to see if the record in question exists

A

T