Skip to content

Instantly share code, notes, and snippets.

@coreyward
Created July 2, 2012 20:26
Show Gist options
  • Select an option

  • Save coreyward/3035488 to your computer and use it in GitHub Desktop.

Select an option

Save coreyward/3035488 to your computer and use it in GitHub Desktop.
If we quit treating <head> as HTML output and started thinking about it more like we do Rack middleware or HTTP headers (i.e. more object-oriented), I think we could gain a lot in the way of flexibility and structure, especially in complex applications.
class ApplicationController < ActionController::Base
head << meta charset: :utf8
head << title 'My Application'
head << stylesheet :application
end
class PostsController < ApplicationController
head << javascript 'fancy_posts_displayer'
def show
@post = Post.find(params[:id])
head << javascript('disqus') if @post.allow_comments?
end
end
class WeirdPagesController < ApplicationController
head.remove stylesheet 'application'
head.before title, meta(:chrome_frame)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment