application_helper.rb
def html_body_attributes
  content_for?(:body_attributes) ? ::Nokogiri::XML("<x>#{content_for(:body_attributes)}</x>").xpath('//x').first.children.each_with_object({}) { |node, obj| obj[node.name] = node.text } : {}
end

application.html.slim
body class=(yield :body_classes) *html_body_attributes
class=(yield :body_classes) 的部份可以忽略,因為我個人會把 <body> class 獨立出來用別的方式給值。

view 裡面使用方法
- content_for(:body_attributes) do
  data-turbolinks="false"
  data-lazy-loading="true"
每個 attribute 之間需要換行,slim 會以 xml 格式輸出,helper 中再 parse XML 以 ruby hash 輸出即可。