To raise a 404 in a controller: raise ActionController::RoutingError, 'Not Found' If a record is accessed and not found, use ActiveRecord::RecordNotFound.