Skip to content

Instantly share code, notes, and snippets.

@holodigm
Forked from hiroshi/gist:985457
Created October 25, 2012 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holodigm/3949756 to your computer and use it in GitHub Desktop.
Save holodigm/3949756 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
...
# FORCE to implement content_for in controller
def view_context
super.tap do |view|
(@_content_for || {}).each do |name,content|
view.content_for name, content
end
end
end
def content_for(name, content) # no blocks allowed yet
@_content_for ||= {}
if @_content_for[name].respond_to?(:<<)
@_content_for[name] << content
else
@_content_for[name] = content
end
end
def content_for?(name)
@_content_for[name].present?
end
end
class PostsController < ApplicationController
def index
content_for :title, "List of posts"
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment