Hide id from url in rails
I am new to rails. I recently developed an app on rails. The app is quite large and works fine. I currently have a url.
http://192.168.99.220/user/13/domainUsers
I want it to be like below (without any id)
http://192.168.99.220/user/domainUsers
My routes are like this.
match 'user/:id/domainUsers', :to => 'domains#manageDomain_2', :as => :manageDomain2
I tried to rewrite the url using "to_param". Because my application is too large and has a lot of functionality, I use parameters other than "id" to find information about users frequently, so I cannot use the "to_param" method. Is there any other way to hide the "id" from the url.
Please, help
Thanks in advance.
+3
source to share
1 answer
The easiest way to do this is to create a gem called friendly_id.
Here's a tutorial that explains it pretty well: http://railscasts.com/episodes/314-pretty-urls-with-friendlyid
+1
source to share