Created
August 29, 2014 14:03
-
-
Save andremedeiros/e5b1c01ec0e7ad6661f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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