scud bomb
scud bomb

Reputation: 417

Rails app Case-sensitive URLs

In our Rails app, our REST architecture curently only allows for case sensitive User URLs. We want our user URLs to appear as ourapp.com/ChrisScutti or ourapp.com/chrisscutti. Definitely dont want to be shoveling out 404s just because someone mistyped their URL based on case.

Upvotes: 1

Views: 93

Answers (2)

Carsten Gehling
Carsten Gehling

Reputation: 1248

This gem will downcase the entire path before route dispatching kicks in.

https://rubygems.org/gems/route_downcaser

This way you don't need to do crazy hacks on each controller.

/ Carsten

Upvotes: 0

miked
miked

Reputation: 4499

Most likely occurring because you are using a case sensitive dbms like PostgreSQL. If so, change the condition you are using to find that user to NOT be case sensitive.

User.where("lower(username) = ?", username.downcase).first

Note, this will not change the appearance of the url in the browser, but it will query using non case sensitive criterion.

Upvotes: 2

Related Questions