Skip to content

Instantly share code, notes, and snippets.

@xtoddx
Created July 16, 2009 21:26
Show Gist options
  • Save xtoddx/148702 to your computer and use it in GitHub Desktop.
Save xtoddx/148702 to your computer and use it in GitHub Desktop.
# examples of using before_render
# http://github.com/xtoddx/before_render
class HiController < ApplicationController
before_render :hook_it_up
before_render :double_hooked, :if => lambda{|x| false}
before_render :cool_action, :only => [:index]
before_render :lousy_action, :except => [:index]
# just the page
# def index; end
def index2
op = render_to_string(:action => 'index')
render :text => op
end
def index3
render :update do |page|
page.assign :cool, @cool_action
page.assign :lousy, @lousy_action
page.assign :hooked, @hooked
page.assign :double_hooked, @double_hooked
end
end
private
def hook_it_up
@hooked = true
end
def double_hooked
@doulbe_hooked = true
end
def cool_action
@cool_action = true
end
def lousy_action
@lousy_action = true
end
end
__END__
<%# VIEW FILE %>
Cool action - <%= h(@cool_action.inspect) %><br/>
Lousy action - <%= h(@lousy_action.inspect) %><br/>
Hooked: <%= h(@hooked.inspect) %><br/>
Double? <%= h(@double_hooked.inspect) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment