Rails Helperで、任意のTagを表示する

ちょっと忘れていたのでメモ。

content_tagの使い方
[ruby]
content_tag(:p, “Hello world!”)
# =>

Hello world!

content_tag(:div, content_tag(:p, “Hello world!”), :class => “strong”)
# =>

content_tag(“select”, options, :multiple => true)
# => …options…

< %= content_tag :div, :class => “strong” do -%>
Hello world!
< % end -%>
# =>

[/ruby]

tagの使い方
[ruby]
tag(“br”)
# =>

tag(“br”, nil, true)
# =>

tag(“input”, { :type => ‘text’, :disabled => true })
# =>

tag(“img”, { :src => “open & shut.png” })
# =>![][1]

tag(“img”, { :src => “open & shut.png” }, false, false)
# =>![][1]
[/ruby]

[1]: open & shut.png

 Share!