メニュー

リファレンス

HTMLタグ逆引き

検索

目次

  1. 本体を持つ任意のタグを生成(content_tag)
  2. モデルから本体を持つ任意のタグを生成(content_tag_for)

<caption>

本体を持つ任意のタグを生成(content_tag)

適応バージョン

  • 1.0.0
  • 1.1.0
  • 1.1.1
  • 1.1.6
  • 1.2.0
  • 1.2.6
  • 2.0.0
  • 2.0.1
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.2
  • 2.3.8
  • 3.0.0
  • 3.0.5
  • 3.0.7
  • 3.0.9
  • 3.1.0
  • 3.2.3
  • 3.2.8
  • 3.2.13
  • 4.0.0

説明

タグを動的に生成
HTMLとERBが混ざってしまう場合などに使用するとすっきり表現できる

使い方

content_tag(タグの名前)

content_tag :p, "Hellow world"
<p>Hellow world</p>

ソースコード

ソースコードを見る
# File /usr/local/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_view/helpers/tag_helper.rb, line 91
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
  if block_given?
    options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
    content_tag_string(name, capture(&block), options, escape)
  else
    content_tag_string(name, content_or_options_with_block, options, escape)
  end
end

ソースコード検索

モデルから本体を持つ任意のタグを生成(content_tag_for)

適応バージョン

  • 1.0.0
  • 1.1.0
  • 1.1.1
  • 1.1.6
  • 1.2.0
  • 1.2.6
  • 2.0.0
  • 2.0.1
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.2
  • 2.3.8
  • 3.0.0
  • 3.0.5
  • 3.0.7
  • 3.0.9
  • 3.1.0
  • 3.2.3
  • 3.2.8
  • 3.2.13
  • 4.0.0

説明

モデルからタグを動的に生成する
HTMLとERBが混ざってしまう場合などに使用するとすっきり表現できる

使い方

content_tag_for(タグの名前, モデル [, オプション])

<%= content_tag_for(:tr, @person) do %>
  <td><%= @person.first_name %></td>
  <td><%= @person.last_name %></td>
<% end %>

ソースコード

ソースコードを見る
# File /usr/local/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_view/helpers/record_tag_helper.rb, line 81
def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block)
  options, prefix = prefix, nil if prefix.is_a?(Hash)

  Array(single_or_multiple_records).map do |single_record|
    content_tag_for_single_record(tag_name, single_record, prefix, options, &block)
  end.join("\n").html_safe
end

ソースコード検索