0
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 3 years have passed since last update.

コントローラとアクションでビューページの分岐をする時

Last updated at Posted at 2019-12-06

ありがちなコントローラーαがAまたはBみたいな分岐を書かなきゃいけない時

悪い例.rb

 if コントローラーα == 'A' || コントローラーα == 'B'

と書いていたんだけど

いい例.rb
 if controller_name.in?(%w(A B))

と短く書くことができる!

これからはcontroller_name.in?を使おう
アクションの判断もaction_name.in?で判断することができる!

##例文


 return render('try/steps') if controller_name.in?(%w(try orders)) && action_name.in?(%w(apply confirm))
0
0
0

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
0
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?