ruby on rails - Is it possible to preprocess the URL before mapping routes? -


we're migrating site proprietary framework ruby on rails (v2.3). current framework puts /base/ @ start of url no discernible reason, , i'd existing url work, though won't give out more.

my current solution, don't like, define routes once on main map , once on 'base' scope:

def draw_routes(map)   # routing here end  actioncontroller::routing::routes.draw |map|   map.with_options :path_prefix => '/base' |base|     draw_map(base)   end    draw_map(map) end 

what i'd like:

actioncontroller::routing::routes.draw |map|   map.strip 'base'    # routing here end 

is there solution of form?

you can write middleware remove base url. in lib/remove_base.rb:

class removebase   def initialize(app)     @app = app   end    def call(env)     env['request_path'].gsub!(/^\/base/, '')     env['path_info'].gsub!(/^\/base/, '')     env['request_uri'].gsub!(/^\/base/, '')     @status, @headers, @response = @app.call(env)     [@status, @headers, self]   end    def each(&block)     @response.each(&block)   end end 

and add line in config/environment.rb

config.middleware.use "removebase" 

i've tested in 2.3.8 mongrel, , seems work.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -