LoginSignup
5
4

More than 5 years have passed since last update.

TextHelper#concat + content_tag のハマりどころ

Last updated at Posted at 2016-01-18

concat と ブロック付きの content_tag を組み合わせてつかうとき、

concat content_tag(:div) do
  concat content_tag(:span, "Sample")
end

とすると、

<div></div> 

と出力されてしまう。

concat(content_tag(:div) do
  concat content_tag(:span, "Sample")
end)

とすれば、

<div><span>Sample</span></div>

期待通りに出力される。

前者の場合、content_tag に付属させることを意図したブロックが実際には concat に渡されるため、とのことです。

参考:stackoverflow

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