LoginSignup
4
1

More than 5 years have passed since last update.

link_to_ifにブロックを渡す

Last updated at Posted at 2018-10-14

link_to_if(link_to_unless)を使う時に、link_toの時と同じようにブロックを渡そうとするとエラーになる

<%= link_to_if 条件式, url do %>
<span>エラーになるよ</span>
<% end %>

captureを使うといい感じにできる

<% @contents = capture do %>
  <span>うごくよ</span>
<% end %>
<% link_to_if 条件式, @contents, url %>
4
1
1

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
4
1