Chapter 6 Flashcards
What is the syntax to generate a model?
$rails generate model singularModelName attribute1:datatype attribute2:datatype
What is the default Rails library used for interacting with a database?
ActiveRecord
What is the difference between model names and controller names?
Controller names are plural
What is a migration?
A way to alter the structure of a database incrementally, so that models can adapt to changing requirements
How do we run the scripts to ‘migrate up’ our database?
$bundle exec rake db:migrate
What is the name of the column Rails generates in the database for each row?
ID; an integer
How do we ‘migrate down’ and undo a database migration?
$bundle exec rake db:rollback
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?
$rails console –sandbox
What is the command to insert a new object into the database?
newObject.save
This method returns a boolean of whether or not it was successful
T/F: an model object created with #new is not saved to the database.
T; It is added to the database with #save
What is special about the model method #create
It makes a new instance of the model and updates the database accordingly, and returns the object
What is the inverse of #create
destroy
What are the Active Record methods to find users?
find, which takes an id integer
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?
instance.reload.attributeName
What is a method to update multiple attributes?
update_attributes(options hash)