ActiveRecord, conventions, controllers, callbacks and background jobs.
A new teammate asks what "ActiveRecord" actually means in Rails. Explain
it both as a design pattern and as the library your models inherit from.
What does a class like class Product < ApplicationRecord give you for free?
You have an Order model and a Customer model. A customer places many
orders; each order belongs to one customer. Write the two association
lines, say which table holds the foreign key, and what happens if you
save an order with no customer.
In a controller you can load a record with Article.find(params[:id]),
Article.find_by(slug: params[:slug]) or
. What does each do when no
matching row exists, and when would you pick each one?
Article.find_by!(slug: params[:slug])What is a scope in an ActiveRecord model and what is it for? Write a
published scope and a recent scope for a Post model and show how
you would use them together.
A Ticket has a status of pending, in progress or closed. A teammate
declares enum :status, { pending: 0, in_progress: 1, closed: 2 }. What is
an ActiveRecord enum, what is stored in the database, and what methods
does this one line give you?
Students enrol in courses, and you need to record the date each student
enrolled and their final grade. Would you model this with
has_many :through or has_and_belongs_to_many? Explain the difference
between the two and justify your choice.