Challenge 1: A Role Column — Solution Migration: $ rails generate migration AddRoleToUsers role:integer # db/migrate/20260105000000_add_role_to_users.rb class AddRoleToUsers < ActiveRecord::Migration[7.1] def change add_column :users, :role, :integer, default: 0 end end Model: # app/models/user.rb class User < ApplicationRecord has_secure_password enum role: { member: 0, admin: 1 } end Controller: # app/controllers/comments_controller.rb class CommentsController < ApplicationController def destroy unless current_user&.admin? redirect_to root_path, alert: "Not authorized" return end Comment.find(params[:id]).destroy redirect_to root_path end end =begin Notes: - default: 0 on the migration means every existing and newly created user defaults to member (0) unless explicitly set to admin (1) -- avoiding a situation where existing users end up with a nil role. - current_user&.admin? uses safe navigation in case current_user itself is nil (no one logged in) -- without it, calling .admin? on nil would raise NoMethodError instead of cleanly failing the authorization check. - return after the redirect_to inside the unless block is important -- without it, execution would continue into the destroy logic below even after already redirecting, which is the same "guard clause" discipline from Ruby Course 2's idioms chapter. =end