I’m using Rails and I have a User Controller for creating new users. To view current users I have to type something like:
mysite.com/users/USER_ID
I want to change to:
mysite.com/USER_ID
What is the best way to acheive that?
Thanks,
Tam
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To improve a bit your generated URLs, you could also add a to_param method to the User model to get something like:
That way, Rails will still work properly (by calling .to_i on your param[:id]) and get better URLs.
Keep in mind that you should remove some special characters from the method you would use, so it should be more likely something like: