module Replica
module_function
def read
ActiveRecord::Base.connected_to(role: :reading, prevent_writes: true) do
yield
end
end
end
class PublicProfilesController < ApplicationController
skip_before_action :authenticate_member!
def show
@profile = Replica.read do
Member.includes(:snips).find_by!(nickname: params[:nickname])
end
end
end
For apps with replicas, route read-only code paths to reading role and enforce prevent_writes. This is a strong reliability move: accidental writes on replicas become exceptions instead of silent data loss.