Skip to content

Instantly share code, notes, and snippets.

@chiedo
Last active May 15, 2026 20:40
Show Gist options
  • Select an option

  • Save chiedo/9ee0d559da53370788a01ee3e12b5e95 to your computer and use it in GitHub Desktop.

Select an option

Save chiedo/9ee0d559da53370788a01ee3e12b5e95 to your computer and use it in GitHub Desktop.
Interview starter — Ruby DismissAndRedirectController (read & extend)

Task — Add a new dismiss/redirect destination (Ruby)

You don't need to know Ruby or Rails. Read carefully, lean on your AI, and tell your interviewer what you see.

This is a sample file to help you get an idea for the type of backend code you'd work on.

  • dismiss_and_redirect_controller.rb — handles GET /in-product-messaging/dismiss-and-redirect?notice=…&destination_key=….
  • dismiss_and_redirect_controller_test.rb — one passing test.

Step 1 (~2 min) — Read it out loud

In your own words:

  1. What does this controller do, and what does the DESTINATION_PATHS map represent?
  2. Why does it wrap the write in ActiveRecord::Base.connected_to(role: :writing) do … end? Reason from the code — the answer is in the method names if you read them carefully.

Step 2 (~3 min) — Extend it

Your team just shipped a new "Get started with our CLI" nudge that lives on the dashboard. The CTA needs to dismiss the nudge and send the user to /copilot/cli.

The nudge id and destination key are both accelerate_ipm_copilot_cli_dashboard_nudge.

Copy the code exerpt to an editor of your choice then make two changes:

  1. Add the new entry to DESTINATION_PATHS in dismiss_and_redirect_controller.rb.
  2. Add a new test in dismiss_and_redirect_controller_test.rb that mirrors the existing one — uses the new notice + destination key, asserts the redirect, asserts the notice was dismissed.

You don't have to run the test. We're assessing reading + diff-writing, not Ruby tooling setup. Use your AI to type if you like; you drive.

How to share your answer

Edit the gist files in the browser and share your screen

# Simplified excerpt of github/github's DismissAndRedirectController.
# Original lives in:
# packages/in_product_targeting/app/public/in_product_targeting/controllers/dismiss_and_redirect_controller.rb
class DismissAndRedirectController < ApplicationController
before_action :login_required
DESTINATION_PATHS = {
"pr_show_ccr_ghec_owner_primary_nudge" => "/enterprises/:business_slug/ai-controls/agents/policies",
"accelerate_ipm_copilot_business_onboarding_modal_copilot" => "/copilot",
"accelerate_ipm_copilot_business_onboarding_modal_agents" => "/copilot/agents",
}.freeze
# GET /in-product-messaging/dismiss-and-redirect
def show
notice = params[:notice]
destination_key = params[:destination_key]
if notice.present?
ActiveRecord::Base.connected_to(role: :writing) do
current_user.dismiss_notice(notice)
current_user.track_nudge_dismissal(id: notice)
end
end
if destination_key.present? && DESTINATION_PATHS.key?(destination_key)
redirect_to DESTINATION_PATHS[destination_key]
else
redirect_to "https://github.com"
end
end
end
# Simplified excerpt of the controller's test file.
# Uses Rails' integration test helpers (sign_in, get, assert_redirected_to).
require "test_helper"
class DismissAndRedirectControllerTest < ActionDispatch::IntegrationTest
setup do
@user = create(:user)
end
test "dismisses notice and redirects to /copilot for the onboarding modal copilot key" do
sign_in(@user)
get "/in-product-messaging/dismiss-and-redirect", params: {
notice: "accelerate_ipm_copilot_business_onboarding_modal_copilot",
destination_key: "accelerate_ipm_copilot_business_onboarding_modal_copilot",
}
assert_redirected_to "/copilot"
assert @user.reload.notice_dismissed?("accelerate_ipm_copilot_business_onboarding_modal_copilot")
end
test "redirects to github.com for an unknown destination_key" do
sign_in(@user)
get "/in-product-messaging/dismiss-and-redirect", params: {
destination_key: "this_key_does_not_exist",
}
assert_redirected_to "https://github.com"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment