LoginSignup
68
65

More than 5 years have passed since last update.

Railsで表示中のページのパスを判定する方法

Posted at

以下のように、current_page?メソッドを用いることによって、表示中のページのパスを判定できる。
これはUrlHelperとして実装されているため、ビューの中から呼び出すことができる。

# root_path かどうか
current_page?(root_path)

# /users/:id が current_user かどうか
current_page?(current_user)

# 任意のコントローラ/アクションかどうか
current_page?(controller: 'foo', action: 'bar')

参考

68
65
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
68
65