I want to encrypt routes in ruby on rails application through routes file.
Sample URL: http://localhost:3000/users or http://localhost:3000/users/1/edit
Encrypted URL: http://localhost:3000/dshfkhjkbkbjkdfjkfdhk or http://localhost:3000/dshfkhjkbkbjkdfjkfdhk/dskjfs/hdfkjdf
It's possible to encrypt using any gem. How to manage all routes encryption at the Application level
Thank you in Advance
You can't. All you can do is implement your own router, and map all encrypted paths to a single controller and let that controller call your router.
# config/routes.rb
match '*path', to: 'encrypted#index', via: :all
class EncryptedController < ApplicationController
def index
path = params[:path]
decrypted_path = path.split('/').map{|part| decrypt(part)}.join('/')
MyRouter.dispatch(request.method, decrypted_path, request)
end
end
module MyRouter
def self.dispatch(request_method, path, request)
# Your own dispatching logic here.
# Note that this method should return a Rack-compatible response.
end
end