LoginSignup
11
12

More than 5 years have passed since last update.

link_to_ifにブロック渡した時の挙動が欲しいのと違う

Posted at

ので、

application_helper.rb
module ApplicationHelper
  def link_to_if_with_block(condition, options = nil, html_options = nil, &block)
    if condition
      link_to(options, html_options, &block)
    else
      capture(&block)
    end
  end
end

ッテの書いた。

hoge.html.haml
= link_to_if_with_block user_signed_in? user_path(current_user) do
  .image
    = user.image
  .name
    = user.name

こんな風に書ける。

11
12
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
11
12