# i've seen a lot of ways to inject css from deep inside rails' views and/or
# paritals into the dom <head />, but this one is my favourite
#


# in application_controller.rb
#
  def style
    @style ||= (
      Hash.new{|h,k| h[k] = Hash.new}
    )
  end
  helper_method :style


# in application_helper.rb
#
  def css_for(style)
    unless style.blank?
      css = []

      style.each do |selector, attributes|
        unless attributes.blank?
          guts = []
          attributes.each do |key, val|
            guts << "#{ key } : #{ val };"
          end
          unless guts.blank?
            css << "#{ selector } { #{ guts.join(' ') } }"
          end
        end
      end

      unless css.empty?
        css.join("\n")
      end
    end
  end

# and, finally, in layouts/application.html.rb
#
  "
    ...

      <style>
        <%= css_for(style) %>
      </style>

    </head>

    ...
  "

# then, in your views, you simple need to do something like
#
  style['#content']['width'] = '50%'
  style['#content']['margin'] = 'auto'


# done and reads super clean!
#