comparison app/controllers/tweets_controller.rb @ 166:469df6354341

A more robust check
author nanaya <me@nanaya.pro>
date Fri, 03 Aug 2018 02:39:09 +0900
parents 5af9b537db86
children af84c9f23263
comparison
equal deleted inserted replaced
165:5af9b537db86 166:469df6354341
1 class TweetsController < ApplicationController 1 class TweetsController < ApplicationController
2 def index 2 def index
3 return redirect if params[:id] || params[:name] 3 return redirect if params[:id].present? || params[:name].present?
4 end 4 end
5 5
6 def show 6 def show
7 return redirect if params[:id][/D/].present? 7 return redirect if params[:id][/D/].present?
8 8
17 rescue Twitter::Error::Unauthorized 17 rescue Twitter::Error::Unauthorized
18 head :forbidden 18 head :forbidden
19 end 19 end
20 20
21 def redirect 21 def redirect
22 @user ||= Tweet.new(params[:id] || params[:name]).user 22 @user ||= Tweet.new(params[:id].presence || params[:name]).user
23 redirect_to tweet_path(@user.id, @user.screen_name) 23 redirect_to tweet_path(@user.id, @user.screen_name)
24 rescue Twitter::Error::NotFound 24 rescue Twitter::Error::NotFound
25 head :not_found 25 head :not_found
26 rescue Twitter::Error::Unauthorized 26 rescue Twitter::Error::Unauthorized
27 head :forbidden 27 head :forbidden