LoginSignup
6
8

More than 5 years have passed since last update.

link_to_ifで条件に応じてリンクを変える

Posted at

例えば条件に応じて「ログイン」「マイページ」とリンクを変える場合。

linlif.html.erb
<%= link_to_if @user.nil?, 'ログイン', controller: :login, action: :index do |name| 
link_to 'マイページ', controller: :login, action: :info 
end %>

(『Ruby on Rails4アプリケーション・プログラミング』より引用)

判定で@userが空の場合は「ログイン」をそうではない場合は「マイページ」のリンクを出力。

6
8
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
6
8