Я люблю использовать помощников Haml, но с годами все немного изменилось. Старый способ заключался в простой конкатенации в буфер. Вот что у меня есть:
def confirmation_table(field)
# Be certain that if the user is logged in, his/her email and name show
if field.respond_to? :user
haml_tag('tr') {
haml_tag('th', 'Email:')
haml_tag('td', field.user.email)
}
haml_tag('tr') {
haml_tag('th', 'Name:')
haml_tag('td', field.user.full_name)
}
else
haml_tag('tr') {
haml_tag('th', 'User Information:')
haml_tag('td', 'Not specified.')
}
end
field.class.columns.collect{|col| col.name}.reject{|col|
col =~ /_at$/ ||
col =~ /_on$/ ||
col =~ /_id$/ ||
col == 'id'}.each do |col|
haml_tag('tr') {
haml_tag('th', ActiveSupport::Inflector::humanize(col))
haml_tag('td', typeize(field, col))
}
end
end
На мой взгляд, к этому, конечно, можно получить доступ просто:
- confirmation_table(@f)
Однако для меня более логично возвращать строку. Я не вижу, как haml_capture
обеспечивает такую же структурирующую способность. Есть намеки?