How can i replicate twitter usernames in URL cas insensitive:
And that all these URL's, opens user page when he has username saved as "MY_Name" or etc.
And Model.find('my_NAmE') method finds user record named MY_Name.
The way you make comparison case insensitive is to normalize the case both in the database and in the search input, so that the search always returns the result no matter the input case.
Always downcase usernames before saving it to the database
Use Model.find(params[:id].to_s.downcase)
or custom method to perform a case insensitive find
There you are.
If you don't want to alter the original username case, then add a second column to the user table where you store the downcased version. Then perform the search on this field instead of the original user field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With