fixed_tag

こんな感じ。

  def fixed_tag(name, options = nil, &block)
    top = options.delete(:top) || 0
    style = options[:style] || ''
    options[:style] = "position:fixed;_position:absolute;top:#{top};_top:expression(eval(document.body.scrollTop+#{top.to_i}));#{style}"
    content = capture(&block)
    concat(content_tag(name, content, options), block.binding)
  end
<% fixed_tag :div, :top => 100, :style => 'left:0; background:lime;' do -%>
  ...
<% end -%>

cssには

body {
  background: url(null) fixed;
}

を追加しておく。


情報源はこのへん。