# HG changeset patch # User nanaya # Date 1603046542 -32400 # Node ID af84c9f23263607a41ba7942920a1109128e357e # Parent d12f671185a872116645608190cb2d89cea46ec7 Fix redirect for twitter user with nil screen name Everything else is still kind of broken but it's kind of beyond help anyway diff -r d12f671185a8 -r af84c9f23263 app/controllers/tweets_controller.rb --- a/app/controllers/tweets_controller.rb Sat Aug 22 04:38:30 2020 +0900 +++ b/app/controllers/tweets_controller.rb Mon Oct 19 03:42:22 2020 +0900 @@ -9,7 +9,7 @@ client = Tweet.new(params[:id].to_i) @user = client.user - return redirect if @user.screen_name != params[:name] + return redirect if normalized_screen_name != params[:name] @tweets = client.timeline rescue Twitter::Error::NotFound @@ -20,10 +20,15 @@ def redirect @user ||= Tweet.new(params[:id].presence || params[:name]).user - redirect_to tweet_path(@user.id, @user.screen_name) + redirect_to tweet_path(@user.id, normalized_screen_name) rescue Twitter::Error::NotFound head :not_found rescue Twitter::Error::Unauthorized head :forbidden end + + private + def normalized_screen_name + @user.screen_name.presence || '_' + end end