12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/path_rewriter/rails.rb', line 12
def install
ActionController::Base::optimise_named_routes = false
ActionController::Routing::Routes.class_eval do
def call_with_rewrite(orig)
env = orig.dup
begin
env["REQUEST_URI"] = PathRewriter::Rails.codec.decode(env["REQUEST_URI"])
call_without_rewrite(env)
rescue ActionController::NotImplemented, ActionController::MethodNotAllowed, ActionController::RoutingError
call_without_rewrite(orig)
end
end
alias_method_chain :call, :rewrite
end
[ ActionController::Base, ActionView::Base ].each do |klass|
klass.class_eval do
def url_for_with_rewrite(*args)
url = url_for_without_rewrite(*args)
PathRewriter::Rails.codec.encode(url)
end
alias_method_chain :url_for, :rewrite
end
end
end
|