正如你所看到的,我有一个帮助器,我正在尝试渲染视图。RoR |如何让content_tags嵌套?
嵌套的content_tags不呈现什么是我关于此标记的断开连接?
def draw_calendar(selected_month, month, current_date)
content_tag(:table) do
content_tag(:thead) do
content_tag(:tr) do
I18n.t(:"date.abbr_day_names").map{ |day| content_tag(:th, day, :escape => false) }
end #content_tag :tr
end #content_tag :thead
content_tag(:tbody) do
month.collect do |week|
content_tag(:tr, :class => "week") do
week.collect do |date|
content_tag(:td, :class => "day") do
content_tag(:div, date.day, :class => (Date.today == current_date ? "today" : nil))
end #content_tag :td
end #week.collect
end #content_tag :tr
end #month.collect
end #content_tag :tbody
end #content_tag :table
end #draw_calendar
:::编辑:::
因此,这里是什么工作。再次感谢mu太短了!
def draw_calendar(selected_month, month, current_date)
tags = []
content_tag(:table) do
tags << content_tag(:thead, content_tag(:tr, I18n.t("date.abbr_day_names").collect { |name| content_tag :th, name}.join.html_safe))
tags << content_tag(:tbody) do
month.collect do |week|
content_tag(:tr, :class => "week") do
week.collect do |date|
content_tag(:td, :class => "day") do
content_tag(:div, :class => (Date.today == current_date ? "today" : nil)) do
date.day.to_s
end #content_tag :div
end #content_tag :td
end.join.html_safe #week.collect
end #content_tag :tr
end.join.html_safe #month.collect
end #content_tag :tbody
tags.join.html_safe
end #content_tag :table
end #draw_calendar
末
与此类似:http://stackoverflow.com/questions/4205613/rails-nested-content-tag你错过了一个'+'(或任何东西)连接'thead'和'tbody' – PeterWong