Skip to content

Instantly share code, notes, and snippets.

@benders
Created May 19, 2011 18:45
Show Gist options
  • Save benders/981431 to your computer and use it in GitHub Desktop.
Save benders/981431 to your computer and use it in GitHub Desktop.
Make sub-requests in Rails 2.3
# PH'NGLUI MGLW'NAFH!
# IA IA IA!
module SubrequestHelper
def get_subrequest_for_uri( uri )
sub_env = request.env.dup
sub_env['REQUEST_URI'] = uri
sub_env['REQUEST_METHOD'] = 'GET'
sub_env['rack.input'] = StringIO.new("")
sub_env.delete('QUERY_STRING')
sub_env.delete_if { |k,v| k =~ /^action_controller/ }
ActionController::Routing::Routes.call(sub_env)[2]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment