Complete the code to define a model class in Rails.
class User < ApplicationRecord # This model represents the users table in the database [1] end
The validates line is a common way to add rules to a model, showing it represents data with validations.
Complete the code to associate a model with another model.
class Post < ApplicationRecord [1] :user end
has_many instead of belongs_to here.The belongs_to association shows that each post is linked to one user, representing data relationships.
Fix the error in the model method that returns a user's full name.
class User < ApplicationRecord def full_name [1] end end
The method should combine first_name and last_name with a space to represent the full name properly.
Fill both blanks to create a scope that finds active users ordered by creation date.
class User < ApplicationRecord scope :active, -> { where([1]: true).order([2]: :desc) } end
status instead of active for filtering.updated_at instead of created_at.The scope filters users where active is true and orders them by created_at descending.
Fill all three blanks to define a model with validations and a method that returns a greeting.
class Customer < ApplicationRecord validates :email, presence: true, uniqueness: true def greet "Hello, [1] [2]!" end scope :[3], -> { where(active: true) } end
email in the greeting instead of names.The method uses first_name and last_name to greet the customer. The scope active_customers filters active customers.