Module: ActionInterceptor::Common

Defined in:
lib/action_interceptor/common.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/action_interceptor/common.rb', line 6

def self.included(base)
  base.alias_method_chain :url_for, :interceptor
end

Instance Method Details

#url_for_with_interceptor(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/action_interceptor/common.rb', line 10

def url_for_with_interceptor(options = {})
  url = url_for_without_interceptor(options)
  return url unless use_interceptor

  @interceptor_url_for_hash ||= is_interceptor ? \
                                intercepted_url_hash : \
                                current_url_hash

  uri = URI(url)
  new_query = Hash[URI.decode_www_form(uri.query || '')]
                .merge(@interceptor_url_for_hash)
  uri.query = URI.encode_www_form(new_query)
  uri.to_s
end