1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

今日のリファクタリング -1

Last updated at Posted at 2019-05-30

お腹ぐるぐるヨーグルト
どうも k1y0です。初めてのqiita投稿。

今日のキニナルコード


before_action :set_content #@content

def show
  if params[:type] == 'programming'
    @title = '速習 プログラミング!'
    @text  = @content.programming_text
  elsif params[:type] == 'food'
    @title = '美味しい焼肉屋さん'
    @text  = @content.food_text
  elsif params[:type] == 'money'
    @title = '爆速で100億稼ぐ方法'
    @text  = @content.money_text
  end
end

こんなコードがありました。

どう変更したか

# before省略
def show
  @title, @text =
  case params[:type]
  when 'programming'
    '速習 プログラミング!', @content.programming_text
  when 'food'
    '美味しい焼肉屋さん', @content.food_text
  when 'money'
    '爆速で100億稼ぐ方法', @content.money_text
  end
end

課題

typeごとにhashとか作ってkeyで受け取った方がわかりやすそう。rubyむずかしい

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?