Skip to content

Instantly share code, notes, and snippets.

@andremedeiros
Created August 29, 2014 14:03
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 andremedeiros/e5b1c01ec0e7ad6661f1 to your computer and use it in GitHub Desktop.
Save andremedeiros/e5b1c01ec0e7ad6661f1 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protected
# Protected: Internally redirects and renders a request.
#
# Example:
#
# def latest
# post = Post.last
# internal_redirect_to controller: 'posts', action: 'show', id: post.id
# end
#
def internal_redirect_to(options={})
controller_name = "#{params[:controller]}_controller".classify
controller_klass = controller_name.constantize
# Set up the instance with the request, response and also the parameters.
controller_instance = controller_klass.new.tap do |c|
c.request = request
c.response = response
c.request.params.merge!(options)
end
controller_instance.process(params[:action])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment