1.Migration is a set of database instructions written in Ruby. The objective of migration is to change database state from one to another.
2.Both of the following commands are equivalent in Rails 5.0+:
rake db:migrate
and
rails db:migrate
3.Assuming there is a model User with attributes of name and occupation, the create method call will create and save a new record into the database as follows:
user = User.create(name: "David", occupation: "Code Artist")
Alternatively the following code will also create a user record but not save it into the database:
user = User.new user.name = "David" user.occupation = "Code Artist"
Which of the following is the correct syntax for committing the user record to the database after the above code?
4.The following model code creates a Student model and maps it to a students table in the database:
class Students < Application Record end
5.Active Record allows you to validate the state of a model before it gets written into the database. One such method is save. What is the difference between the user.save! and user.savemethods?
| user.save! is stricter in that it raises the exception ActiveRecord::RecordInvalid if validation fails. |
| Both user.save and user.save! are the same functionally |
| user.save is stricter in that it raises the exception ActiveRecord::RecordInvalid if validation fails. |