Module: Adva::Controller::InternalRedirect

Defined in:
lib/adva/controller/internal_redirect.rb

Instance Method Summary collapse

Instance Method Details

#internal_redirect_to(target, params = nil) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/adva/controller/internal_redirect.rb', line 7

def internal_redirect_to(target, params = nil)
  action, controller = target.split('#').reverse
  controller ||= controller_path

  params ||= self.params
  params.merge!(:controller => controller, :action => action)
  params = yield(params) if block_given?

  rack_endpoint = "#{controller}_controller".classify.constantize.action(action)
  env['action_dispatch.request.parameters'] = params
  response = rack_endpoint.call(env)

  self.status, self.headers, self.response_body = response
  @_response.headers.replace(response[1])

  response
end