当前位置: 首页 > 工具软件 > Markaby > 使用案例 >

#69 Markaby in Helper

夏侯昆琦
2023-12-01
Do you ever need to generate HTML code in a helper method? Placing it directly in Ruby strings is not very pretty. Learn a great way to generate HTML through Markaby in this episode.
def simple_error_messages_for(object_name)
object = instance_variable_get("@#{object_name}")
return if object.errors.empty?

markaby do
div.error_messages! do
h2 "#{pluralize(object.errors.count, 'error')} occurred"
p "There were problems with the following fields:"
ul do
object.errors.each_full do |msg|
li msg
end
end
end
end
end

def markaby(&block)
Markaby::Builder.new({}, self, &block)
end
 类似资料:

相关阅读

相关文章

相关问答